PHPMailer-OpenSSL错误 [英] PHPMailer - OpenSSL Error

查看:103
本文介绍了PHPMailer-OpenSSL错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于PHPMailer提供的示例,我的脚本如下,

Based on the example that PHPMailer provides i have the script below,

date_default_timezone_set('Etc/UTC');
require './PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "myemail@example.com";
$mail->Password = "********";
$mail->setFrom('myMail@example.com', 'First Last');
$mail->addReplyTo('myEmail@example.com', 'First Last');
$mail->addAddress('toEmail@example.com', 'first last');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->Body = "example";
$mail->AltBody = 'This is a plain-text message body';

if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}

即使这与原始示例完全相同,我也无法使其正常工作.

Even if that is the exactly the same as the original example, i cannot get it to work.

我得到的错误是

警告:stream_socket_enable_crypto():SSL操作失败,代码为1.OpenSSL错误消息:error:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在/opt/lampp/htdocs/webmail_client_practise/class中失败.smtp.php,第344行 SMTP错误:无法连接到SMTP主机.

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /opt/lampp/htdocs/webmail_client_practise/class.smtp.php on line 344 SMTP Error: Could not connect to SMTP host.

通知:我的php.ini文件中的OpenSSL扩展名已经打开.

Notice: The OpenSSL extension in my php.ini file is already opened.

推荐答案

这是因为您正在运行PHP 5.6,并且正在验证您的证书,但是您的服务器提供的证书无效,因此失败了. PHPMailer和PHP都在做正确的事情-代码没有错.您可以修复邮件服务器,也可以按照故障排除指南中的建议进行操作,是:

This is because you're running PHP 5.6 and it's verifying your certs, but your server is presenting invalid certs so it's failing. Both PHPMailer and PHP are correct in what they are doing - the code is not at fault. You can either fix your mail server, or do what it suggests in the troubleshooting guide, which is:

$mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

并且如指南所述,除非必须这样做,否则不应该这样做-这会损害您的安全性.

And as the guide says, you should not do this unless you have to - it's compromising your security.

这篇关于PHPMailer-OpenSSL错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆