Opened 9 years ago
Closed 9 years ago
#36219 closed defect (bug) (duplicate)
wp_mail_failed action returns an empty WP_Error object
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.6 |
Component: | Keywords: | ||
Focuses: | Cc: |
Description
In pluggable.php's wp_mail() function, directly after wp_mail() calls PHPMailer's send() operation, it catches a phpmailerException exception and uses that to create a WP_Error object that get's passed to the do_action() method.
WP_Error's constructor requires the code parameter not to be empty. If it is empty, WP_Error does not construct the WP_Error object.
The phpmailerException returned from the send() operation does not contain an error code when an invalid From address was specified (probably other several other conditions also), which results in the following line of code returning an empty WP_Error object:
do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );
This could be fixed by first testing if $e->getCode() is empty and if it is, then rather to default a code such as "wp_mail_phpmailer_error", or similar.
Hey there, welcome to trac and thanks for creating this ticket!
We're already tracking this issue in #35598. There's also a suggested patch to fix this behaviour and I'd encourage you to test it.
See https://make.wordpress.org/core/handbook/testing/patch/ for details about testing a patch.