尝试使用CodeIgniter ON WINDOWS发送电子邮件时出现以下错误:
Severity: Warning
Message: failed loading cafile stream: `C:\OpenSSL\cert\cacert.pem'
Filename: libraries/Email.php
Line Number: 2055
我也遇到了这些错误:
Severity: Warning
Message: fsockopen(): Failed to enable crypto
Filename: libraries/Email.php
Line Number: 2055
并且:
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
Filename: libraries/Email.php
Line Number: 2055
此代码之前正在运行,但在我将php版本升级到5.6
后开始抛出此错误修改
根据其他帖子的建议,我决定将我的脏手放在CodeIgniter的电子邮件类上,并用 stream_socket_client()替换对 fsockopen()的调用:
$context = stream_context_create(['ssl' => [
'ciphers' => 'RC4-MD5',
'cafile' => 'C:/OpenSSL/cert/cacert.pem',
]]);
//$this->_smtp_connect = fsockopen($ssl.$this->smtp_host, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);
$this->_smtp_connect = stream_socket_client($ssl.$this->smtp_host.':'.$this->smtp_port, $errno, $errstr, $this->smtp_timeout, STREAM_CLIENT_CONNECT, $context);
但是,我仍然得到上述相同的3个错误。
fsockopen()和 stream_socket_client()这两个事实引发了关于不加载cafile的相同错误这一事实真的很奇怪。