awesomemotive / WP-Mail-SMTP

The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 3 million sites.
https://wordpress.org/plugins/wp-mail-smtp/
GNU General Public License v3.0
55 stars 35 forks source link

`wp_mail_failed` is not fired. #44

Closed websupporter closed 5 years ago

websupporter commented 5 years ago

wp_mail() provides an action, you can utilize to log when mails are not send: wp_mail_failed. So, if the PHPMailer throws an error, it will be catched by wp_mail() and this action will be fired.

In order to tell PHPMailer to throw those exceptions and not to catch them an never release them, you have to instantiate PHPMailer like this: $phpmailer = new PHPMailer( true ); https://github.com/WordPress/WordPress/blob/931f8046d3ab430b6b355428f8d85d9ab1591d1f/wp-includes/pluggable.php#L221

The true boolean will tell PHPMailer to throw the errors.

WP Mail SMTP extends the PHPMailer with its own MailCatcher class and replaces the default implementation here: https://github.com/awesomemotive/WP-Mail-SMTP/blob/f8aca0b8310f027985b96e7e0fc82e784202d64f/src/Core.php#L555-L560

As you can see, the boolean is not set and this means it defaults to false. This basically disables all functionality which hooks into wp_mail_failed.

slaFFik commented 5 years ago

Good catch.

This will be fixed in the next release of the WP Mail SMTP plugin.

Thank you!

PS We have own wp_mail_smtp_providers_mailer_is_email_sent filter, that can be used to check whether the email was successfully sent.

websupporter commented 5 years ago

Thanks a lot @slaFFik.

websupporter commented 5 years ago

Hi @slaFFik, just a quick reminder :)

I checked the current version 1.4.2 on wp.org and it seems, the problem is still there: https://plugins.trac.wordpress.org/browser/wp-mail-smtp/tags/1.4.2/src/Core.php#L467

slaFFik commented 5 years ago

@websupporter It will be released in 1.5.0 :) 1.4.2 was a compatibility (with plugins repository guidelines) release.

websupporter commented 5 years ago

Just updated. wanted to leave a thx @slaFFik :heart: