返回邮件在 Yii 2 的基本邮件类中发送失败的错误


Returning the error why mail failed to send within Yii 2's base mailer class

我正在使用Yii 2并且正在使用基本邮件类中的邮件程序,并且在大多数情况下它工作正常,但有时它无法发送.....所以我的代码是这样的:

// Let's start composing the message
$mail = Yii::$app->mailer->compose($view_data, $view_params);
//.........
// Send the message
$send = $mail->send();      

有时$sendfalse但我不确定你是如何发现为什么它是假的?有没有办法得到使它变成错误的错误?

如果您要发送多个收件人消息,则应检查失败: http://swiftmailer.org/docs/sending.html#getting-failures-by-reference,例如:

if (Yii::$app->mailer->getSwiftMailer()->send($message->getSwiftMessage(), $failures))    
{
    // do what you want with $failures var
}

如果你真的想在你的yii应用程序中处理smtp错误,你应该使用swiftmailer记录器插件:http://swiftmailer.org/docs/plugins.html#logger-plugin

PS :首先我会检查 yii 和 smtp 日志,看看发生什么样的错误......