2016-08-03 3 views
-1

メールにCSSクラスをカット私はテンプレートを使用して電子メールを送信:yii2は

  $content='Message'; 
     Yii::$app->mailer->compose('@app/mail/templates/templ', ['content'=>$content]) 
     ->setFrom('[email protected]') 
     ->setTo('[email protected]') 
     ->setSubject('Message subject') 
     ->send(); 

そして、私のテンプレート:

<?php 
use yii\helpers\Html; 

/* @var $this \yii\web\View view component instance */ 
/* @var $message \yii\mail\MessageInterface the message being composed */ 
/* @var $content string main view render result */ 
?> 
<?php $this->beginPage() ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=<?= Yii::$app->charset ?>" /> 
    <style type="text/css"> 
     .footer { 
     color: red; 
     } 
    </style> 
    <?php $this->head() ?> 
</head> 
<body> 
<?php $this->beginBody() ?> 
<?= $content ?> 
<div class="footer">With kind regards </div> 
<?php $this->endBody() ?> 
</body> 
</html> 
<?php $this->endPage() ?> 

私は私の電子メールを読んだとき、私はそのCSSクラスが動作しません見ることができます。クラス 'フッター'も。 この問題を解決するにはどうすればよいですか?

答えて

1

これはYii 2の問題ではありません。ほとんどの電子メールクライアントは、要素に直接適用されないとCSSスタイルを無視します。

そのことについて素晴らしい記事があります - Using CSS in HTML Emails: The Real Story

+0

おかげで、私はそれを読んであげるには、 –