[wp-trac] [WordPress Trac] #25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names

WordPress Trac noreply at wordpress.org
Fri Dec 27 00:37:46 UTC 2013


#25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names
-------------------------------------------------+-------------------------
 Reporter:  layotte                              |       Owner:
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Mail                                 |  Review
 Severity:  normal                               |     Version:  3.8
 Keywords:  has-patch dev-feedback needs-        |  Resolution:
  testing                                        |
-------------------------------------------------+-------------------------

Comment (by sreedoap):

 I wanted to note my use case for this which caused me to run into this
 issue. I am calling wp_install from a command line script I made which is
 ran for our users who launch a WordPress site, so HTTP_HOST and
 SERVER_NAME were not set for me. I manually set it in my script and that
 fixed my issue but it would probably be wise for the wp_mail function to
 have a fallback if it is unable to get a valid value from HTTP_HOST or
 SERVER_NAME so emails don't appear to come from an "unknown sender".

 Replying to [ticket:25239 layotte]:
 > For quite some time I have been having an issue with my comment
 notifications. The From address has been wordpress at _. I haven't paid much
 attention to this, but I had some spare time and decided to pursue the
 issue. Here it is...
 >
 > I am running WPMS w/ domains (latest stable) with Nginx and PHP5-FPM. In
 WordPress the comment notifications from email addresses are being
 generated using `$_SERVER['SERVER_NAME']` to get the current site's domain
 name.
 >
 > e.g.
 > {{{
 > $wp_email = 'wordpress@' . preg_replace('#^www\.#', '',
 strtolower($_SERVER['SERVER_NAME']));
 > }}}
 >
 > However, because of my environment my Nginx config for my site has the
 server_name set to "_" (underscore). Which is a catchall --
 http://nginx.org/en/docs/http/server_names.html.
 >
 > Site config in Nginx:
 > {{{
 > # Redirect everything to the main site.
 > server {
 >         listen [::]:80 default_server;
 >         listen [::]:443 ssl;
 >
 >         ssl_certificate         /etc/nginx/ssl.crt/xxx.com.2012.crt;
 >         ssl_certificate_key     /etc/nginx/ssl.key/xxx.com.2012.key;
 >
 >         server_name _;
 >         root /var/www/xxx.com;
 >         access_log /var/log/nginx/xxx.com.access.log;
 >         error_log /var/log/nginx/xxx.com.error.log;
 >         client_max_body_size 100m;
 >
 >         if ($http_host = "www.xxx.com") {
 >                 rewrite ^ http://xxx.com$request_uri permanent;
 >         }
 >
 >         include global/restrictions.conf;
 >
 >         # Additional rules go here.
 >
 >         include global/wordpress-ms.conf;
 >
 > }
 > }}}
 >
 > The default fastcgi_params has this set:
 > {{{
 > fastcgi_param   SERVER_NAME             $server_name;
 > }}}
 >
 > Thus, `$_SERVER['SERVER_NAME']` is outputting "_" (underscore).
 >
 > I propose we move away from `$_SERVER['SERVER_NAME']` when generating
 the from email addresses and use the available $current_site global object
 which stores the domain variable ($current_site->domain). I have
 implemented this change on my own site and have included the patch here.
 >
 > In the meantime, anyone else facing this problem can change their
 fastcgi_param to $host instead of $server_name. In my opinion, not the
 best solution, but it works for now.

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25239#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list