PhpMailer引发致命异常 [英] PhpMailer throwing Fatal Exceptions

查看:351
本文介绍了PhpMailer引发致命异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在循环的邮件程序脚本,正在处理来自服务器的外发电子邮件.有时会挂断并显示以下错误.

I have a mailer script that is looping, processing outgoing emails from my server. Occasionally it hangs up with the following error.

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

这导致我的脚本在消息提示完成之前就消失了.

This causes my script to die before the reminder of the messages can complete.

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

Here is the code that kicks off the email.

$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();
}

我似乎没有捕捉到异常.我该如何优雅地恢复呢?

I don't seem to be catching the exception. How can I recover from this gracefully?

编辑

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

It was a namespace issue as indicated below.

推荐答案

最有可能是名称空间错误-偷偷摸摸的错误.

Most likely a namespace error - the sneakiest of errors.

catch (\phpmailerException $e)

这篇关于PhpMailer引发致命异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆