66beta
V2EX  ›  PHP

WordPress 和 php.ini 里面都设置了时区为 Asia/Shanghai,但是发出去的邮件时间依然是 0 时区的?

  •  
  •   66beta · Jul 31, 2014 · 4194 views
    This topic created in 4319 days ago, the information mentioned may be changed or developed.
    其实很简单的代码:
    $str = date("H:i:s");
    wp_mail('[email protected]', 'send testing', "This email is from Wordpress send at $str");

    如果直接在页面输出,时区是对的

    问题是用wp_mail发送到gmail后,看到是0时区的时间(这时间只是邮件的正文而已,不是邮件的发送时间~)

    从代码来讲 $str = date("H:i:s"); 每次都获取当前时间,为啥,为啥???
    Supplement 1  ·  Jul 31, 2014
    写插件的时候,需要使用WP自己的函数 current_time("H:i:s");
    http://codex.wordpress.org/Function_Reference/current_time
    4 replies    2014-07-31 16:00:37 +08:00
    msg7086
        1
    msg7086  
       Jul 31, 2014   ❤️ 1
    输出在页面与发邮件是同一个上下文?

    会不会是wp自己改掉了默认时区?
    kmvan
        2
    kmvan  
       Jul 31, 2014 via Android   ❤️ 1
    直接用mail时间有没错?
    66beta
        3
    66beta  
    OP
       Jul 31, 2014
    @msg7086 @kmvan
    我擦,是WP的插件系统的设定问题

    写插件的时候,需要使用WP自己的函数 current_time("H:i:s");
    http://codex.wordpress.org/Function_Reference/current_time
    msg7086
        4
    msg7086  
       Jul 31, 2014
    "In WordPress, PHP's time() will always return UTC"

    看来猜对了。我觉得你应该能猜到像WP这样的系统在初始化的时候会reset掉各种东西。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5621 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 06:12 · PVG 14:12 · LAX 23:12 · JFK 02:12
    ♥ Do have faith in what you're doing.