如何解决phpmailer中的此错误?当我几个月前进行测试时,这从未发生过。
2019-06-18 15:26:33 Connection: opening to ssl://localhost:465, timeout=300, options=array ( )
2019-06-18 15:26:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): Peer certificate CN=`server18.hostingraja.org' did not match expected CN=`localhost'
2019-06-18 15:26:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): Failed to enable crypto
2019-06-18 15:26:33 Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://localhost:465 (Unknown error)
2019-06-18 15:26:33 SMTP ERROR: Failed to connect to server: (0)
2019-06-18 15:26:33 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting`
答案 0 :(得分:0)
错误消息告诉您确切的问题是什么
对等证书CN =
server18.hostingraja.org' did not match expected CN=
本地主机'
因此,您的代码(未显示)可能正在执行以下操作:
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Host = 'localhost`;
这行不通,因为您无法获得localhost
的可验证证书。解决此问题的两种方法:
$mail->SMTPSecure = false;
$mail->Port = 25;
这只是禁用了加密,您不需要加密,因为您只连接到本地主机。
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Host = 'server18.hostingraja.org`;
这样,您仍然可以连接到同一台服务器,但是使用正确的名称,以便可以验证证书。
如果还有其他问题,请阅读错误消息链接到的故障排除指南,并在发布前进行搜索。