Opened 8 years ago
Last modified 7 years ago
#40390 new defect (bug)
Wrong time (and date) in mail header send by phpmailer
Reported by: | Drivingralle | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.7.3 |
Component: | Keywords: | ||
Focuses: | Cc: |
Description
I noticed that some mail clients show wrong time and sometimes date (around midnight) while forwarding or otherwise dealing with emails. For ex. MS Outlook gets it wrong.
The offset is the same as my local timeoffset to UTC.
Tracking it down this is because the rfcDate()
within wp-includes/class-phpmailer.php uses date_default_timezone_get()
to add the date and time into the mail header. This value is forced by WP to be UTC.
Debugging rfcDate() with:
error_log( var_export( date_default_timezone_get(), true ) ); error_log( var_export( date('D, j M Y H:i:s O'), true ) ); error_log( var_export( current_time( 'D, j M Y H:i:s O' ), true ) );
I get:
[07-Apr-2017 12:01:02 UTC] 'UTC' [07-Apr-2017 12:01:02 UTC] 'Fri, 7 Apr 2017 12:01:02 +0000' [07-Apr-2017 12:01:02 UTC] 'Fri, 7 Apr 2017 14:01:02 +0000'
I read this ticket #39595 and I guess it will not be changed.
The ticket also says there is no WP function using the native timezone getter. This shows there is. Or at least a lib within core.
Can we modify the phpmailer class to use current_time()
or do we need to set and reset the timezone before and after every phpmailer call?
Note that
current_time()
itself callsdate()
and assumes default timezone. In other words it will ignore WP time zone and output completely invalid stuff unlessgmt
arg is set to true.So your last suggestion to use
current_time()
will just increase breakage. :(I am not sure why would times be "wrong" without more context. If
date()
without input is used they would be correct, just always in UTC (which consuming email clients should be able to display in desired time zone I would assume).The more likely issue is that WP API is feeding broken input into mailer class.
PS chimed in on
current_time()
issue in https://core.trac.wordpress.org/ticket/38940#comment:8