PHPMailer error on new user creation with WP Multi-Network - solution anyone?

Hi everyone,

I hope someone can help…

I’m using EE Wordpress (4.6.1) Multisite Subdomain with the WP Multi-Network plugin.

Everything works as expected, except when I create a new user, the new user email doesn’t get sent and the server sends a 500 error.

Going back to the users list, it turns out the user was actually created, but the error log shows:


2016/11/15 16:40:51 [error] 22467#22467: *242 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught exception 'phpmailerException' with message 'Invalid address: wordpress@_' in /var/www/mysite.co.uk/htdocs/wp-includes/class-phpmailer.php:946
Stack trace:
#0 /var/www/mysite.co.uk/htdocs/wp-includes/pluggable.php(352): PHPMailer->setFrom('wordpress@_', 'WordPress', false)
#1 /var/www/mysite.co.uk/htdocs/wp-includes/ms-functions.php(1243): wp_mail('jason.levy@lond...', 'New User Regist...', 'New User: prunk...')
#2 [internal function]: newuser_notify_siteadmin(18)
#3 /var/www/mysite.co.uk/htdocs/wp-includes/plugin.php(524): call_user_func_array('newuser_notify_...', Array)
#4 /var/www/mysite.co.uk/htdocs/wp-includes/ms-functions.php(1067): do_action('wpmu_new_user', 18)
#5 /var/www/mysite.co.uk/htdocs/wp-admin/network/user-new.php(49): wpmu_create_user('prunking', 'GX8U0mkl6BsW', 'first.health.lt...')
#6 {main}
  thrown in /var/www/mysite.co.uk/htdo" while reading response header from upstream, client: 141.101.99.9, server: _, request: "POST /wp-admin/network/user-new.php?action=add-user HTTP/1.1", upstream: "fastcgi://unix:/run/php5-fpm.sock:", host: "www.networksite.co.uk", referrer: "https://www.networksite.co.uk/wp-admin/network/user-new.php"

My sites-available/mysite.co.uk looks like:


listen 80 default_server;
listen 443 ssl http2 default_server;

#server_name www.networksite.co.uk www.mysite.co.uk;
# Uncomment the following line for domain mapping
server_name _;

# Uncomment the following line for domain mapping
server_name_in_redirect off;

Whether I request www.networksite.co.uk or www.mysite.co.uk, WP Multi-Network serves the correct domain, so nginx must be sending the domain name to Wordpress.

If I comment out server_name _; and switch back to server_name www.networksite.co.uk www.mysite.co.uk;

then the email gets sent. However, the sender is always [email protected], even if I add the user when I’m logged in to www.mysite.co.uk

Has anyone else had this problem, or even if not, can you offer a solution?

Thanks, Jason

I had the same issue and this is how I solved it.

In short WordPress grabs the server name through $_SERVER[ 'SERVER_NAME' ] which looks at server_name in your NGINX config. If that is set to _ it’ll attempt to send the email from wordpress@_ and you’ll get an error.

This solved my issue:

add_filter('wp_mail_from', 'new_mail_from');

function new_mail_from($old) { $url = get_site_url(); $find = array( 'http://', 'https://', 'www.' ); $replace = ''; $sitename = str_replace( $find, $replace, $url ); $from_email = 'wordpress@' . $sitename; return $from_email; }

1 Like

You could set server_name networksite.co.uk; in your nginx site config file. It’s the default server so all requests (not caught by another nginx site) should end up there anyway. You might also make sure the same domain is set in /etc/mailname