2016-04-01 16 views
0

良好的下午!如何爲此郵件添加樣式?我用swiftmailer庫使用YII2。這是我的例子:將樣式應用於YII2中的電子郵件(Gmail不允許我)

$a = Yii::$app -> mailer -> compose() 
-> setFrom('') 
-> setTo('') 
-> setSubject('My title') 
-> setTextBody('Plain text content') 
-> setHtmlBody('My text') 
-> send(); 

郵件/佈局/ html.php

<?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"> 
    .tg {border-collapse:collapse;border-spacing:0;border-color:#ccc;} 
    .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:0px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#fff;border-top-width:1px;border-bottom-width:1px;} 
    .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:0px;overflow:hidden;word-break:normal;border-color:#ccc;color:#333;background-color:#f0f0f0;border-top-width:1px;border-bottom-width:1px;} 
    .tg .tg-yw4l{vertical-align:top} 
    .tg .tg-b7b8{background-color:#f9f9f9;vertical-align:top} 
    </style> 
    <title><?= Html::encode($this->title) ?></title> 
    <?php $this->head() ?> 
</head> 
<body> 
    <?php $this->beginBody() ?> 
    <?= $content ?> 
    <?php $this->endBody() ?> 
</body> 
</html> 
<?php $this->endPage() ?> 

Greethings!

回答

0

在項目腳手架,你應該有

郵件/佈局/ html.php

郵件目錄這裏面的內容

<?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 ?>" /> 
     <title><?= Html::encode($this->title) ?></title> 
     <?php $this->head() ?> 
    </head> 
    <body> 
     <?php $this->beginBody() ?> 
     <?= $content ?> 
     <?php $this->endBody() ?> 
    </body> 
    </html> 
    <?php $this->endPage() ?> 

我在這方面的建議,你的格式和風格

+0

我沒加,但不行,讓我看看我的更新。 – Annon

相關問題