【发布时间】:2017-02-03 06:35:34
【问题描述】:
我正在尝试使用view 在Yii2 中发送电子邮件,但未发送。这是我在controller 做的事情:
$message = Yii::$app->mailer->compose('reportview-html', [
'positiveReviews' => $positiveReviews,
'negativeReviews' => $negativeReviews,
'company_name' => $userSurveyConfig->survey_email_from
])->setFrom([\Yii::$app->params['supportEmail'] => "Review Fox"])
->setTo($userSurveyConfig->reports_email_address)
->setSubject("Review Fox Weekly/Monthly Report")
->send();
这是我的config 邮件设置:
'mail' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@frontend/mail',
'useFileTransport' => false, //set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.gmail.com',
'username' => '**********************',
'password' => '********',
'port' => '465',
'encryption' => 'ssl',
],
],
当我运行脚本时,它不只是发送email,而是当我尝试发送没有视图的电子邮件时,正文中的简单纯文本,它确实发送了电子邮件。
我究竟做错了什么?有什么帮助吗?
【问题讨论】:
-
我知道你在配置本身中设置了路径,你可以尝试注释掉并直接尝试这个 ** Yii::$app->mailer->compose('@frontend/mail /layouts/reportview-html',['model' => $model, 'path' => $path,'password' => $password])**
-
@MohanPrasad 试过了,结果一样。
标签: php email yii2 swiftmailer