我正在使用Swift邮件程序从我基于Yii2的Web应用程序发送电子邮件。但它无法在MS Outlook中正确读取/接收。
请参阅我使用MS Outlook 2010收到的电子邮件正文 -
--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Dear Admin,=20
User John has been si= gned up
successfully.
Thanks,
The App Tea=
m
This message was sent to john@example.com. If y= ou don't want
to receive future emails from ABC, please unsubs= cribe.
--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.=
org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=3D"http://www.w3.org=
/1999/xhtml">
<head>
<meta http-equiv=3D"Content-Type" con= tent=3D"text/html;
charset=3DUTF-8" />
<title></title>
<=
/head>
<body>
Dear Admin, <br>
<p>User John has been signed up successfully.</p>
<=
p>Thanks,</p>
<p>The ABC Team</p>
<br><br><br> =
=09
<p style=3D'color: #B6B6B6'>
This message was sent to =
john@example.com. If you don't want to receive future emai= ls
from ABC, please <a href=3D'#'>unsubscribe</a>.
</p> =
</body>
</html>
--_=_swift_v4_1430198154_31f7ff2886dc0fb65796db153d9434096acbae54_=_--
我正在使用以下配置进行编码 -
'messageConfig' => [
'charset' => 'UTF-8',
],
使用 -
发送Yii::$app->mailer->compose('mailview', ['name' => $name])
->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->name . ' App'])
->setTo($to)
->setSubject($subject)
->send();
我错过了什么?
答案 0 :(得分:0)
对我来说只有setHtmlBoby()方法, 因为来自文档的示例发送了带有重复内容的3个标题:
下面是代码示例:
//render view content
$htmlMailContent = $this->renderPartial('@common/mail/passwordCreateToken-html', ['user' => $model]);
//render layout
$htmlMail = $this->renderPartial('@common/mail/layouts/html', ['content' => $htmlMailContent]);
$mailResult = Yii::$app->mailer->compose()
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name . ' robot'])
->setTo($model->email)
->setSubject('Password reset for ' . Yii::$app->name)
->setHtmlBody($htmlMail) //set here mail with layout
->send();