【问题标题】:PhpMailer throwing Fatal ExceptionsPhpMailer 抛出致命异常
【发布时间】:2012-04-13 20:12:09
【问题描述】:

我有一个循环的邮件脚本,处理从我的服务器传出的电子邮件。有时它会因以下错误而挂起。

PHP Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP Error: Data not accepted.'

这会导致我的脚本在消息提醒完成之前终止。

这是启动电子邮件的代码。

$message = new \PHPMailer(true);
$message -> IsSMTP();
try
{
    $message -> SMTPAuth = true;
    $message -> Host = Config::HOST;
    $message -> Port = Config::PORT;
    $message -> Username = $account;
    $message -> Password = Config::PASS;
    $message -> AddReplyTo($account, Config::NAME);
    $message -> SetFrom($account, Config::NAME);
    $message -> AddAddress($recipient[0], $recipient[1]." ".$recipient[2]);
    $message -> Subject = $recipient,$this->subject;
    $message -> AltBody = 'Please enable HTML viewing in order to view this message. Thank you.';
    $message -> MsgHTML($recipient,$this->body);
    if($attachment !== false)
        $message->AddAttachment($attachment);
    $message -> Send();
}
catch (phpmailerException $e)
{
    return $error -> errorMessage();
}
catch (Exception $e)
{
    return $error -> getMessage();
}

我似乎没有发现异常。我怎样才能优雅地从这种情况中恢复过来?

编辑

这是一个命名空间问题,如下所示。

【问题讨论】:

  • 您是否尝试过将实例化和IsSMTP() 调用放在try 中?
  • @Treffynnon 此错误是由未捕获的异常引起的。这是操作试图捕获的异常......而不是错误本身。
  • @JasonGeorge 虽然您确实无法捕获致命错误,但您当然可以尝试捕获导致导致致命错误的异常。
  • 可能是命名空间错误,试试这个:'catch (\phpmailerException $e)'

标签: php try-catch phpmailer


【解决方案1】:

很可能是命名空间错误 - 最隐秘的错误。

catch (\phpmailerException $e)

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 1970-01-01
    • 2015-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多