【问题标题】:PHPMailer date_default_timezone_get(): It is not safe to rely on the system's timezone settings [duplicate]PHPMailer date_default_timezone_get():依赖系统的时区设置是不安全的[重复]
【发布时间】:2017-11-20 07:28:28
【问题描述】:

错误:可用 Erro na Linha:#3274 :: date_default_timezone_get():依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符。我们现在选择时区“UTC”,但请设置 date.timezone 以选择您的时区。 C:\AppServ\www\class\phpmailer.class.php Erro no envio do e-mail: SMTP connect() failed.

public static function rfcDate()
{
    // Set the time zone to whatever the default is to avoid 500 errors
    // Will default to UTC if it's not set properly in php.ini
    date_default_timezone_set(@date_default_timezone_get());
    return date('D, j M Y H:i:s O');
}

【问题讨论】:

    标签: php date datetime


    【解决方案1】:

    PHP 没有设置默认时区。

    在使用 PHPMailer(或任何使用时区的类)之前,您应该通过在 PHP.INI 中设置 date.timezone 来配置 PHP

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = 'Australia/Sydney'
    

    或通过在您的代码中调用 date_default_timezone_set() 函数(在 PHPMailer 之前)

    date_default_timezone_set('Australia/Sydney');
    

    或在 apache 的配置文件中(我的首选方法)

    # Timezone and other stuff for PHP
    php_value date.timezone "Australia/Sydney"
    

    【讨论】:

      【解决方案2】:

      您应该首先使用date_default_timezone_set 来设置默认时区,然后使用 date_default_timezone_get.

      date_default_timezone_set — 设置所有使用的默认时区 脚本中的日期/时间函数

      date_default_timezone_get — 获取所有使用的默认时区 脚本中的日期/时间函数

      一个例子是:

      date_default_timezone_set('America/Los_Angeles');
      
      $x= date_default_timezone_get(); // 'America/Los_Angeles'
      

      您当前正在尝试请求默认时区,以便将其值用于您的date_default_timezone_set 调用,但它从未设置为开头。

      【讨论】:

      • 问题中的代码不是用户代码。它是 PHPMailer 的一部分,但这个答案也是正确的。
      猜你喜欢
      • 2012-09-14
      • 2014-01-11
      • 2014-07-18
      • 2017-05-22
      • 2011-01-13
      • 2011-08-07
      • 2011-08-27
      • 2015-07-13
      相关资源
      最近更新 更多