[wp-trac] [WordPress Trac] #40810: wp_mail fails to send email on WP auto update when wp-cron is called directly by php

WordPress Trac noreply at wordpress.org
Sat Jul 29 20:55:02 UTC 2017


#40810: wp_mail fails to send email on WP auto update when wp-cron is called
directly by php
--------------------------------------+------------------------------
 Reporter:  pessoft                   |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Mail                      |     Version:  4.7.5
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:  administration
--------------------------------------+------------------------------
Description changed by SergeyBiryukov:

Old description:

> Hi!
>
> On some of our WordPress instances wp-cron.php is called by system cron
> directly as a parameter to php command ( not via HTTP request ). This is
> partially to make sure that WP cron is executed regularly and partially
> to make sure that all tasks in cron will not hit a timeout for HTTP
> communication on servers and reverse proxies.
>
> In a case when WP triggers auto update during such php execution and
> wants to send email about success, there is no $_SERVER['SERVER_NAME']
> available and no From: header passed to wp_mail, therefore sender's email
> is not fully generated and delivery fails:
> PHP Fatal error:  Uncaught exception 'phpmailerException' with message
> 'Invalid address:  (setFrom) wordpress@'
>
> There are at least three possible solutions which could generate valid
> email address and maybe help in more scenarios too:
>
> 1) WP auto update fix
> As WP update knows what is the site URL of WP during update, it could
> construct sender's email directly from configuration, pass it as From:
> header to wp_mail and not need to rely on whether SERVER_NAME is set or
> not.
>
> 2) Local hostname fix
> When wp_mail is called and From: header is not present, wp_mail tries to
> construct the sender's email from SERVER_NAME. In case neither
> SERVER_NAME is available, wp_mail could try to call function like
> php_uname or gethostname yet as a last resort for construction of
> sender's email. This could ( at least to some extent ) help with such
> wp_mail calls where SERVER_NAME is not available.
>
> 3) Sender's email configuration option
> By providing possibility to have a default sender's email for WP
> configured, it would be possible to use such address as sender in wp_mail
> function and rely on SERVER_NAME only if configuration option would be
> not set ( or set empty ). Based on history of tickets related to sender's
> email address, this fix would help many users for which current
> construction of sender's address is not suitable and work also in
> backward compatible way.
>
> Do you see any of these options acceptable?
>
> Thanks.

New description:

 Hi!

 On some of our WordPress instances wp-cron.php is called by system cron
 directly as a parameter to php command ( not via HTTP request ). This is
 partially to make sure that WP cron is executed regularly and partially to
 make sure that all tasks in cron will not hit a timeout for HTTP
 communication on servers and reverse proxies.

 In a case when WP triggers auto update during such php execution and wants
 to send email about success, there is no `$_SERVER['SERVER_NAME']`
 available and no From: header passed to wp_mail, therefore sender's email
 is not fully generated and delivery fails:
 {{{
 PHP Fatal error:  Uncaught exception 'phpmailerException' with message
 'Invalid address:  (setFrom) wordpress@'
 }}}

 There are at least three possible solutions which could generate valid
 email address and maybe help in more scenarios too:

 1) WP auto update fix
 As WP update knows what is the site URL of WP during update, it could
 construct sender's email directly from configuration, pass it as From:
 header to wp_mail and not need to rely on whether `SERVER_NAME` is set or
 not.

 2) Local hostname fix
 When wp_mail is called and From: header is not present, wp_mail tries to
 construct the sender's email from `SERVER_NAME`. In case neither
 `SERVER_NAME` is available, wp_mail could try to call function like
 `php_uname` or `gethostname` yet as a last resort for construction of
 sender's email. This could ( at least to some extent ) help with such
 wp_mail calls where `SERVER_NAME` is not available.

 3) Sender's email configuration option
 By providing possibility to have a default sender's email for WP
 configured, it would be possible to use such address as sender in wp_mail
 function and rely on `SERVER_NAME` only if configuration option would be
 not set ( or set empty ). Based on history of tickets related to sender's
 email address, this fix would help many users for which current
 construction of sender's address is not suitable and work also in backward
 compatible way.

 Do you see any of these options acceptable?

 Thanks.

--

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40810#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list