gpt4 book ai didi

exception-handling - Yii2 如何处理 Swift_TransportException 异常?

转载 作者:行者123 更新时间:2023-12-04 07:52:59 26 4
gpt4 key购买 nike

尝试使用 swiftmailer 发送邮件时,出现以下错误:

Expected response code 250 but got code "550", with message "550 User test@test.com has exceeded its 24-hour sending limit. Messages to 250 recipients out of 250 allowed have been sent. Relay quota will reset in 1.47 hours.

我已将 swiftmailer 放在 try catch 块中,如下所示:
public function sendMail($emailTemplateName, $subject, $body, $fromEmail, $toEmail)
{
try
{
return Yii::$app->mailer->compose(['html' => $emailTemplateName], ['emailBody' => $body])
->setFrom([ $fromEmail => Yii::$app->params['siteTitle'] ])
->setTo($toEmail)
->setSubject($subject)
->send();
}
catch(Swift_SwiftException $exception)
{
return 'Can sent mail due to the following exception'.print_r($exception);
}
}

我也试过 Swift_SwiftExceptionException但异常(exception)不会被捕获。

我该如何处理这个异常?

最佳答案

好的,我知道了。我需要使用 \Swift_TransportException在 catch 。

关于exception-handling - Yii2 如何处理 Swift_TransportException 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30093259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com