yii2削减了电子邮件中的css类

时间:2016-08-03 10:38:40

标签: html css email yii2 swiftmailer

我使用模板发送电子邮件:

         $content='Message';
         Yii::$app->mailer->compose('@app/mail/templates/templ', ['content'=>$content])
        ->setFrom('gorobets.asya@gmail.com')
        ->setTo('nastya.g2410@gmail.com')
        ->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课程不起作用。 Class&#39;页脚&#39;也。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

这不是Yii 2问题。如果不直接应用于元素,大多数电子邮件客户端都会忽略css样式。

关于这一点的文章很棒 - Using CSS in HTML Emails: The Real Story