如何在 Yii2 邮件程序中向多个收件人发送邮件或如何在 yii2 邮件程序中添加 setCc [英] How to send mail to multiple recipients in Yii2 mailer OR how to add setCc in yii2 mailer
本文介绍了如何在 Yii2 邮件程序中向多个收件人发送邮件或如何在 yii2 邮件程序中添加 setCc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 Yii2 邮件程序中向多个收件人发送邮件?
此代码用于多个收件人但不起作用.
This code for a multiple recipient but not working.
$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,但这也不起作用.
This code for adding setCc but this is also not working.
$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();
推荐答案
我刚刚尝试了以下代码,并且可以正常工作.您的代码中唯一奇怪的地方似乎是在带有数组的 setFrom 中.
I just tried the following code, and it's working. The only things strange in your code seems to be in the setFrom with an Array.
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 邮件程序代码中有以下注释:
In the Swift mailer code there is the following comments :
* 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.
希望有帮助.
这篇关于如何在 Yii2 邮件程序中向多个收件人发送邮件或如何在 yii2 邮件程序中添加 setCc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文