PHPMailer function set_magic_quotes_runtime() is deprecated

测试代码

$mailer = new Mailer();
$mailer->FromName = 'BigData Tech Team';
$mailer->Subject = "【报警提醒】广告主[{$adv_id}]充值异常";
$body = "广告主:{$adv_id}<br>";

$mailer->MsgHTML($body);
$mailer->AddAddress('bigdate-adsta@sohu-inc.com');
$mailer->AddAddress('clarechen@sohu-inc.com');
$mailer->AddAttachment('/tmp/test.txt');
$mailer->Send();
$mailer->ClearAddresses();

结果正文信息正常,无附件信息,然后使用$mailer->ErrorInfo打印错误信息,提示
function set_magic_quotes_runtime() is deprecated

方法在php 5.3后弃用,查看具体调用的地方,发现

private function EncodeFile($path, $encoding = 'base64') {
  try {
    if (!is_readable($path)) {
      throw new phpmailerException($this->Lang('file_open') . $path, self::STOP_CONTINUE);
    }
    if (function_exists('get_magic_quotes')) {
      function get_magic_quotes() {
        return false;
      }
    }
    if (PHP_VERSION < 6) {
      $magic_quotes = get_magic_quotes_runtime();
      set_magic_quotes_runtime(0);
    }
    $file_buffer  = file_get_contents($path);
    $file_buffer  = $this->EncodeString($file_buffer, $encoding);
    if (PHP_VERSION < 6) { set_magic_quotes_runtime($magic_quotes); }
    return $file_buffer;
  } catch (Exception $e) {
    $this->SetError($e->getMessage());
    return '';
  }
}

在上述方法中调用,但是PHP_VERSION < 6 判断有问题,即 字符串 ‘5.6.3’ < 6 为true
所以导致这个问题出现。

鉴于无法修改PHP_VERSION, 故引入swiftmailer扩展支持当前业务。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值