Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger breaks if no array passed from wp_mail #94

piersb opened this issue Jul 23, 2019 · 1 comment


Copy link

piersb commented Jul 23, 2019

In our workflow we used a different mailer by intercepting the call to wp_mail. Because wp_mail was never passed its arguments, wp-mail-logging throws a Fatal Error.

Steps to replicate: Add a function which intercepts the call to wp_mail and doesn't pass on the arguments. Below is a trivial example to reproduce the problem.

add_filter('wp_mail', function(){return null;});

Expected result: Either a PHP Warning, or a note in the logging page saying that wp-mail-logging hasn't received the arguments it was expecting.

Actual result:

Fatal error: Uncaught Exception: The message is not valid because it contains no message or html field. in /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-content/plugins/wp-mail-logging/src/WPML_MailExtractor.php:37 Stack trace: #0 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-content/plugins/wp-mail-logging/src/WPML_MailExtractor.php(19): No3x\WPML\WPML_MailExtractor->extractMessage(NULL) #1 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-content/plugins/wp-mail-logging/src/WPML_Plugin.php(214): No3x\WPML\WPML_MailExtractor->extract(NULL) #2 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-includes/class-wp-hook.php(286): No3x\WPML\WPML_Plugin->log_email(NULL) #3 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-includes/plugin.php(208): WP_Hook->apply_filters(NULL, Array) #4 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-includes/pluggable.php(186): apply_filters('wp_mail', Array) #5 /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-content/plugins/wp- in /Users/piersb/Development/Den/dezeenjobs/_project/_web/wp-content/plugins/wp-mail-logging/src/WPML_MailExtractor.php on line 37


This comment has been minimized.

Copy link

No3x commented Sep 12, 2019

The docs say wp_mail filter must be called with arguments.
Plugin API/Filter Reference/wp mail

(array) (required) A compacted array of wp_mail() arguments, including the "to" email, subject, message, headers, and attachments values.

Catching this exception can be done very easy here

$mail = (new WPML_MailExtractor())->extract($mailArray);
to prevent errors. But why is this filter called without args at all? Is there a convention to support this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.