首页 > 解决方案 > Phpmailer 错误:无法验证

问题描述

我知道有很多类似的问题,我已经阅读了所有内容,在评论中尝试了所有内容。还是不行。

我已经为这个项目创建了 gmail 帐户,并从一开始就设置了不太安全的应用程序使用配置。如果有人能给我任何想法,我会非常感激,几个月来我一直在努力解决这个问题。

这是输出:

“ 2018-06-03 21:03:33 服务器-> 客户端:2018-06-03 21:03:33 SMTP 注意:在检查是否连接 SMTP 错误时捕获 EOF:无法验证。SMTP 错误:无法验证。消息尚未发送。邮件程序错误:SMTP 错误:无法验证。> "

这是我的 send.php 代码:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
require 'vendor/autoload.php';

if(isset($_REQUEST['send']))
{
    $name= $_REQUEST['name'];
    $tel= $_REQUEST['tel'];
    $email= $_REQUEST['email'];
    $preference= $_REQUEST['preference'];
    $area= $_REQUEST['area'];
    $message= $_REQUEST['message'];

$mail = new PHPMailer(true);                              
try {                                                     
    $mail->SMTPDebug = 3;                                 
    $mail->isSMTP();                                      
    $mail->Host = 'smtp.gmail.com';                      
    $mail->SMTPAuth = true;                               
    $mail->Username = 'mygmailaccount@gmail.com';           
    $mail->Password = 'thepassword';                  
    $mail->SMTPSecure = 'TSL';                         
    $mail->Port = 587;     
    $mail->CharSet= 'UTF-8';

    // Port 465 for SSL auth. Also tried 587 for authenticated TLS

    $mail->setFrom($email, $name);
    $mail->addAddress('mygmail@gmail.com', 'Myname');     

    $mail->isHTML(true);          
    $mail->Subject = "Contact from ".$name;
    $mail->Body = "Name:". $name. ". </br> Tel:". $tel. ". </br> Email:". $email. ". </br> Preference:". $preference. ". </br> Area:". $area. ". </br> Message:". $message. ". </br> ";

    $mail->AltBody = "Name:". $name. ". ::: Tel:". $tel. ". ::: Email:". $email. ". ::: Preference:". $preference. ". ::: Area:". $area. ". ::: Message:". $message. ". ::: ";

    $mail->send();
    $_SESSION["success"] = "Thanks for the message";

    }
catch (Exception $e)
    {
    echo 'Message hasnt been sent. Mailer Error: ', $mail->ErrorInfo;
    }

}

编辑:我已经尝试了 Abdulla 和 Glass 所说的,停用了 2 步验证并更改为 tsl 端口 587 和调试 3 并获得以下输出:

2018-06-03 22:03:55 连接:打开 smtp.gmail.com:587,超时 = 300,选项 = array() 2018-06-03 22:03:55 连接:打开 2018-06-03 22 :03:55 服务器-> 客户端:220 smtp.gmail.com ESMTP u74-v6sm3867212qku.55 - gsmtp 2018-06-03 22:03:55 客户端-> 服务器:EHLO localhost 2018-06-03 22:03:55服务器 -> 客户端:250-smtp.gmail.com 为您服务,[190.2.100.71]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8 2018-06-03 22:03:55 客户端 -> 服务器: 2018-06-03 22:03:56 服务器-> 客户端:220 2.0.0 准备启动 TLS 2018-06-03 22:03:56 连接失败。错误 #2:stream_socket_enable_crypto():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:ssl3_get_server_certificate:证书验证失败 [H:\xampp\htdocs\mati\PHPMailer\src\SMTP. [php line 406] SMTP 错误:无法连接到 SMTP 主机。2018-06-03 22:03:56 客户端-> 服务器:退出 2018-06-03 22:03:56 服务器-> 客户端:2018-06-03 22:03:56 SMTP 错误:退出命令失败:2018- 06-03 22:03:56 连接:关闭 SMTP 错误:无法连接到 SMTP 主机。El mensaje no ha sido enviado。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。

Edit2:已解决,我已上传到使用 tsl 身份验证的临时服务器中,并且运行良好。我非常感谢@abdulla-nilam 和@mr-glass 的贡献。它最终发送了消息,再次感谢您。起初它在我的本地主机上不起作用,但在临时服务器中工作得很好。

标签: phpemailsmtpgmailphpmailer

解决方案


我认为你应该试试这个:

$mail = new \PHPMailer(true); 
$mail->CharSet = 'UTF-8'; $mail->isHTML(); 
$mail->Host = ...//my config 
$mail->Port = ...//my port $mail->isSMTP(); 
if (version_compare(PHP_VERSION, '5.6.0') >= 0){ 
$mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ), );
 }

推荐阅读