我正在运行一些单元测试,其中一个测试检查电子邮件的生成和发送。
我检查了文档,以强制Yii将电子邮件保存到文件中,而不是发送我配置的mailer
组件如下:
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true
],
在运行测试时,我看到来自Yii::info
函数的BaseMailer send()
消息。
yii\mail\BaseMailer::发送电子邮件“直接借方付款通知”至“test@test.co.uk”
然而,电子邮件没有保存在任何地方,应该是runtime/mail
,它也没有发送到任何地方。
我尝试在运行时使用以下方法设置useFileTransport
:
$mailer = Yii::$app->mailer;
$mailer->useFileTransport = true;
$mailer->composer...
但是没有任何改变,任何帮助都是值得感激的。
发布于 2018-09-06 11:36:09
发布于 2018-09-06 11:26:38
查看Docs,如果启用了yii\mail\BaseMailer::useFileTransport
,此选项将强制将邮件消息数据保存到本地文件中,而不是常规发送。这些文件将保存在yii\mail\BaseMailer::fileTransportPath
下,默认情况下这是@runtime/mail
。
因此,检查您的目录权限,如果它们是正常的,您可以通过使用fileTransportPath
将其更改为您知道不会出现权限问题的任何其他目录。
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
'fileTransportPath'=>'your/path',
],
https://stackoverflow.com/questions/52201553
复制相似问题