From 75048987d8d334b8d541d046a3eb0a3b67a11c12 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Fri, 24 Jul 2020 17:38:27 +0000 Subject: [PATCH] Mail: Ensure that a server hostname can be set by using `network_home_url()`. Due to the varying server setups, `$_SERVER['SERVER_NAME'];` can't reliably ensure that there will be a relevant host that could be used as the hostname in an email. Since the `network_home_url()` is set at this point, and is filterable, this should better enable emails to be sent from the server. Fixes #25239. Props layotte, SergeyBiryukov, nacin, sreedoap, szepe.viktor, jesin, kitchin, mensmaximus, mt8.biz, Grzegorz.Janoszka, cbutlerjr, dd32, BjornW, neodjandre, BjornW, Ipstenu, ocean90, danielbachhuber, desmith, joemcgill, jdgrimes, riasat, derekakelly, swissspidy, lilmike, tsimmons, robert.peake, DavidAnderson, cloudstek, pigdog234, BjornW, rawrly, pessoft, RedSand, seayou, dvershinin, bastho, chesio, Starbuck, afragen, ocean90, whyisjake. git-svn-id: https://develop.svn.wordpress.org/trunk@48601 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 8 ++++---- src/wp-includes/pluggable.php | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 583d4a213c..bfb2b157e1 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -952,7 +952,7 @@ function wpmu_signup_blog_notification( $domain, $path, $title, $user_login, $us $admin_email = get_site_option( 'admin_email' ); if ( '' === $admin_email ) { - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; + $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); } $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; @@ -1079,7 +1079,7 @@ function wpmu_signup_user_notification( $user_login, $user_email, $key, $meta = $admin_email = get_site_option( 'admin_email' ); if ( '' === $admin_email ) { - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; + $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); } $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; @@ -1663,7 +1663,7 @@ We hope you enjoy your new site. Thanks! $admin_email = get_site_option( 'admin_email' ); if ( '' === $admin_email ) { - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; + $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); } $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; @@ -1755,7 +1755,7 @@ function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) $admin_email = get_site_option( 'admin_email' ); if ( '' === $admin_email ) { - $admin_email = 'support@' . $_SERVER['SERVER_NAME']; + $admin_email = 'support@' . wp_parse_url( network_home_url(), PHP_URL_HOST ); } $from_name = ( '' !== get_site_option( 'site_name' ) ) ? esc_html( get_site_option( 'site_name' ) ) : 'WordPress'; diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 0af4eb42d2..c614ac0ed6 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -330,7 +330,7 @@ if ( ! function_exists( 'wp_mail' ) ) : */ if ( ! isset( $from_email ) ) { // Get the site domain and get rid of www. - $sitename = strtolower( $_SERVER['SERVER_NAME'] ); + $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST ); if ( 'www.' === substr( $sitename, 0, 4 ) ) { $sitename = substr( $sitename, 4 ); } @@ -1650,7 +1650,7 @@ if ( ! function_exists( 'wp_notify_postauthor' ) ) : $notify_message .= sprintf( __( 'Spam it: %s' ), admin_url( "comment.php?action=spam&c={$comment->comment_ID}#wpbody-content" ) ) . "\r\n"; } - $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', strtolower( $_SERVER['SERVER_NAME'] ) ); + $wp_email = 'wordpress@' . preg_replace( '#^www\.#', '', wp_parse_url( network_home_url(), PHP_URL_HOST ) ); if ( '' === $comment->comment_author ) { $from = "From: \"$blogname\" <$wp_email>"; @@ -2831,4 +2831,3 @@ if ( ! function_exists( 'wp_text_diff' ) ) : return $r; } endif; -