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/
Stack trace:
#0 /var/www/ PHPMailer->setFrom('wordpress@_', 'WordPress', false)
#1 /var/www/ wp_mail('jason.levy@lond...', 'New User Regist...', 'New User: prunk...')
#2 [internal function]: newuser_notify_siteadmin(18)
#3 /var/www/ call_user_func_array('newuser_notify_...', Array)
#4 /var/www/ do_action('wpmu_new_user', 18)
#5 /var/www/ wpmu_create_user('prunking', 'GX8U0mkl6BsW', '')
#6 {main}
  thrown in /var/www/" while reading response header from upstream, client:, server: _, request: "POST /wp-admin/network/user-new.php?action=add-user HTTP/1.1", upstream: "fastcgi://unix:/run/php5-fpm.sock:", host: "", referrer: ""

My sites-available/ looks like:

listen 80 default_server;
listen 443 ssl http2 default_server;

# Uncomment the following line for domain mapping
server_name _;

# Uncomment the following line for domain mapping
server_name_in_redirect off;

Whether I request or, 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;

then the email gets sent. However, the sender is always, even if I add the user when I’m logged in to

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; 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