【问题标题】:Phpmailer error: Could not authenticatePhpmailer 错误:无法验证
【发布时间】:2018-11-13 05:38:48
【问题描述】:

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

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

这是输出:

" 2018-06-03 21:03:33 服务器-> 客户端: 2018-06-03 21:03:33 SMTP 通知:EOF 在检查是否已连接时被捕获 SMTP 错误:无法验证。 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, timeout=300, options=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 本地主机 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 客户端-> 服务器:STARTTLS 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 第 406 行] SMTP 错误:无法连接到 SMTP 主机。 2018-06-03 22:03:56 客户端-> 服务器:退出 2018-06-03 22:03:56 服务器-> 客户端: 2018-06-03 22:03:56 SMTP 错误:QUIT 命令失败: 2018-06-03 22:03:56 连接:关闭 SMTP 错误:无法连接到 SMTP 主机。 El mensaje no ha sido enviado。邮件程序错误:SMTP 错误:无法连接到 SMTP 主机。

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

【问题讨论】:

  • 你试过port = 587而不是465吗?您是否尝试过 SMTPSecure = 'TLS' 而不是 'SSL'?您的调试输出显示什么?您可能需要更改 SMTPDebug = 3 以获取更多详细信息。
  • chagne 到 $mail-&gt;SMTPSecure = 'tls'; 并确保 两步验证 已关闭
  • 问题很可能是您的原始服务器具有过时的 CA 证书。这个确切的问题及其多种解决方案在错误消息链接的指南中。

标签: php email smtp gmail phpmailer


【解决方案1】:

我认为你应该试试这个:

$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, ), );
 }

【讨论】:

    猜你喜欢
    • 2016-01-16
    • 1970-01-01
    • 2011-04-26
    • 2017-08-19
    • 1970-01-01
    • 2018-08-04
    • 2016-07-14
    • 2021-05-16
    相关资源
    最近更新 更多