WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#39360 closed defect (bug) (fixed)

wp_mail throws a phpmailerException when the sender address is incorrect

Reported by: xknown Owned by: dd32
Milestone: 4.8 Priority: normal
Severity: normal Version: 4.6.1
Component: Mail Keywords:
Focuses: Cc:

Description

The default implementation of wp_mail causes a PHP fatal due to an uncaught phpmailerException exception when the From address contains an invalid email address.
I noticed this error while trying to install WP on a local ubuntu 16.04 VM with PHP 7.1 and the default nginx config (the WP dir was in /var/www/html/wordpress/).

server {
	listen 80 default_server;
	root /var/www/html;
	index index.php index.html index.htm index.nginx-debian.html;
	server_name _;
	location / {
		try_files $uri $uri/ /index.php?$args;
	}
	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/run/php/php7.1-fpm.sock;
	}
}

On the last install step, the VM http server responsed with a 500 error page --- the installation seems to have completed though. Here's the stack trace:

PHP message: PHP Fatal error:  Uncaught phpmailerException: Invalid address: wordpress@_ in /var/www/html/wordpress/wp-includes/class-phpmailer.php:946
Stack trace:
#0 /var/www/html/wordpress/wp-includes/pluggable.php(352): PHPMailer->setFrom('wordpress@_', 'WordPress', false)
#1 /var/www/html/wordpress/wp-admin/includes/upgrade.php(395): wp_mail('alex@buayacorp....', 'New WordPress S...', 'Your new WordPr...')
#2 /var/www/html/wordpress/wp-admin/includes/upgrade.php(98): wp_new_blog_notification('test', 'http://128.199....', 1, 'The password yo...')
#3 /var/www/html/wordpress/wp-admin/install.php(375): wp_install('test', 'alex', 'alex@buayacorp....', 1, '', '...', 'en_US')
#4 {main}

Attachments (3)

39360-tests.diff (773 bytes) - added by xknown 3 months ago.
Unit tests to reproduce this issue.
39360-tests.2.diff (632 bytes) - added by xknown 3 months ago.
Simpler test
39360.diff (1.6 KB) - added by dd32 3 months ago.

Download all attachments as: .zip

Change History (5)

@xknown
3 months ago

Unit tests to reproduce this issue.

@xknown
3 months ago

Simpler test

@dd32
3 months ago

#1 @dd32
3 months ago

  • Milestone changed from Awaiting Review to 4.8

39360.diff is a patch which catches this fatal error, it doesn't attempt to set a proper sender email address though.

I'm going to redirect conversation for setting a proper sender address over to #25239, leaving this ticket open to get rid of the fatal. I feel like this should probably be pushed into 4.7.1 too.

#2 @dd32
3 months ago

  • Owner set to dd32
  • Resolution set to fixed
  • Status changed from new to closed

In 39655:

Mail: Ensure that any phpmailerException exceptions generated by setFrom() are caught to avoid PHP Fatal errors.

This change avoids a PHP fatal error that can be encountered when the specified (or generated) source email is an invalid address, such as wordpress@_, it makes no effort to set a valid source, only avoid the fatal error.

See #25239 for correcting the email address.
Fixes #39360.

Note: See TracTickets for help on using tickets.