【问题标题】:Yii2 How to handle Swift_TransportException exception?Yii2 如何处理 Swift_TransportException 异常?
【发布时间】:2015-05-07 06:15:42
【问题描述】:

当尝试使用 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-handling yii2 swiftmailer yii2-advanced-app


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      相关资源
      最近更新 更多