解决升级PHP7.1后,发邮件时提示“fsockopen,: Peer certificate CN=`xxx.xx.com' did not match expected CN=`113.x.xx.98”

把项目环境升级到PHP7.1后,发现在不使用SSL时可以使用IP发邮件,可设置成SSL时就只能使用hostname发送,PHP提示的错误信息大致意思是说,IP与hostname无法通过SSL验证,修改ci框架中Email类第2061行,结果又可以正常发邮件了,故作此记录。

// 修改的代码
$ctx = stream_context_create(array(
    'ssl' => array(
        'verify_peer_name' => FALSE,
    )
));
$this->_smtp_connect = stream_socket_client(
    $ssl . $this->smtp_host . ':' . $this->smtp_port, 
    $errno,
    $errstr, 
    $this->smtp_timeout,
    STREAM_CLIENT_CONNECT,
    $ctx
);

// 注释原来的代码
// $this->_smtp_connect = @fsockopen($ssl.$this->smtp_host,
//                     $this->smtp_port,
//                     $errno,
//                     $errstr,
//                     $this->smtp_timeout);

!!!根据官网及多数网站建议使用hostname代替IP!!!