doudun3910 2015-04-28 11:46
浏览 56

在Yii2中使用Swift邮件发送电子邮件发送了错误的电子邮件内容

I am using Swift mailer to send email from my Yii2 based web applications. But it can't read/receive in MS Outlook correctly.

Please see the email body bellow which I received using 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_=_--

I am using following configuration for encoding-

 'messageConfig' => [
    'charset' => 'UTF-8',
],

And sending using -

Yii::$app->mailer->compose('mailview', ['name' => $name]) 
            ->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->name . ' App'])
            ->setTo($to)
            ->setSubject($subject)
            ->send();

What am I missing?

  • 写回答

1条回答 默认 最新

  • doukuilian8365 2016-06-29 13:38
    关注

    for me help only setHtmlBoby() method, because example from documentation sends 3 headers with repeating content:

    1. Content-Type: multipart/alternative;
    2. Content-Type: text/plain; charset=utf-8
    3. Content-Type: text/html; charset=utf-8

    Below code example:

    //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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大