如何在Yii2邮件程序中向多个收件人发送邮件或如何在yii2邮件程序中添加setCc

前端之家收集整理的这篇文章主要介绍了如何在Yii2邮件程序中向多个收件人发送邮件或如何在yii2邮件程序中添加setCc前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在Yii2邮件程序中向多个收件人发送邮件

代码适用于多个收件人但无法正常工作.

$value = Yii::$app->mailer->compose()
            ->setFrom([$this->email => $this->name])
            ->setTo(array($model->email_1,$model->email_2))
            ->setSubject($model->status)
            ->setHtmlBody($model->description)
            ->send();

如何在yii2邮件程序中添加setCc?

代码用于添加setCc,但这也无效.

$value = Yii::$app->mailer->compose()
            ->setFrom([$this->email => $this->name])
            ->setTo($model->email_1)
            ->setCc($model->email_2)
            ->setSubject($model->status)
            ->setHtmlBody($model->description)
            ->send();
我刚刚尝试了以下代码,它正在运行.
您的代码中唯一奇怪的东西似乎是在带有Array的setFrom中.
Yii::$app->mailer->compose()
            ->setFrom('addrs1@gmail.com')
            ->setTo(array('addrs1@gmail.com','addrs2@hotmail.com'))
            ->setCc(array('addrs3@gmail.com'))
            ->setSubject('Sending Email')
            ->setTextBody('This is Plain text content')
            ->setHtmlBody('Please go to  <a href="http://google.com/">GOOGLE</a>')
            ->send();

在Swift邮件代码中有以下注释:

* Set the From address of this message.
 *
 * It is permissible for multiple From addresses to be set using an array.
 *
 * If multiple From addresses are used,you SHOULD set the Sender address and
 * according to RFC 2822,MUST set the sender address.

希望能帮助到你.

原文链接:https://www.f2er.com/php/137835.html

猜你在找的PHP相关文章