Reputation: 7002
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?
EDIT
It was a namespace issue as indicated below.
Upvotes: 0
Views: 4713
Reputation: 102250
Most likely a namespace error - the sneakiest of errors.
catch (\phpmailerException $e)
Upvotes: 4