How do you check for the actual error in SwiftMailer v4 when send() fails
Is there a way to check for error when sending mail using SwiftMailer version 4? I am not referring to getting a list of recipient emails that got rejected, and I am not talking about just knowing whether send() worked or not.
I am talking about knowing the actual error that took place during the sending 开发者_高级运维process - such as not able to connect to STMP host, incorrect login, etc.
Simply check the return code from SwiftMailer's send() or batchSend() commands for a non-zero result. If you get a non-zero result (i.e. TRUE), then it succeeded connecting and authenticating to your SMTP service.
From the documentation:
//Send the message
$numSent = $mailer->send($message);
printf("Sent %d messages\n", $numSent);
// Note that often that only the boolean equivalent of the
// return value is of concern (zero indicates FALSE)
if ($mailer->send($message))
{
echo "Sent\n";
}
else
{
echo "Failed\n";
}
精彩评论