I’m using wordpress with the WP Mail SMTP plugin in order to send emails via authenticated SMTP. I have now got it opened at the SMTP server so that we can relay there and the Test mail works – reports true and the mail arrives. However, if I try sending using wp_mail from my plugin it doesn’t work – wp_mail returns false and the email does not arrive. I put some debugging code in the wp_mail function, including that I debug out the
$e->getMessage() from the catch block in the try/catch at the very end of wp_mail (when it tries to send the actual mail). This says
SMTP Error: Could not authenticate.
However, as said, the test mails work!
I then started debugging out the phpmailer object and comparing between my wp_mail call and that for the test mail. I noticed that the
exceptions protected member was true for mine and not for the test mail. It appears that the global phpmailer does not exist when coming in to wp_mail in my call, so it is created in wp_mail using
$phpmailer = new PHPMailer( true ) If I change that true to a false (i.e. set exceptions to false in the phpmailer object) then not only does wp_mail return true but the mail arrives!
How can I be getting authentication errors if I check for exceptions but the mail still be arriving if I don’t check for exceptions? Any ideas?
I’m running wordpress 3.7.1 and WP Mail SMTP 0.9.3 in my development environment. I am experiencing the same symptoms (test mail works but not my wp_mail calls) in wordpress 3.6.1 with version 0.9.1 of the plugin
It appears that the Test Email function continues to try and send the email even if authentication fails. The mail server seems to allow me to relay even without authenticating so the Test Email gets through. Actual calls to wp_mail from my plugin fail if the authentication fails. If I turn of SMTP authentication then my mails work as well.
I think this is a bug in the Test Email functionality, but I’ll take that up with the plugin author.