【问题标题】:Message could not be sent. Mailer Error: SMTP Error: Could not authenticate无法发送消息。邮件程序错误:SMTP 错误:无法验证
【发布时间】:2021-03-07 11:11:54
【问题描述】:

伙计们,我也面临同样的问题,例如无法发送邮件错误,我在谷歌上搜索并尝试了所有方法,但仍然遇到同样的问题 请帮我解决我的错误

方法一:

我允许不太安全的应用程序

方法二:

我输入正确的电子邮件和密码

<?php 

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

require 'vendor/autoload.php'; 

$mail = new PHPMailer(true); 

try { 
    $mail->SMTPDebug = 2;                                    
    $mail->isSMTP();                                             
    $mail->Host  = 'smtp.gmail.com;';                    
    $mail->SMTPAuth = true;                          
    $mail->Username = '****@gmail.com';              
    $mail->Password = '*******';                         
    $mail->SMTPSecure = 'tls';                           
    $mail->Port  = 587; 

    $mail->setFrom('*************', 'Name');         
    $mail->addAddress('*****************'); 
    $mail->addAddress('***********', 'Name'); 
    
    $mail->isHTML(true);                                 
    $mail->Subject = 'Subject'; 
    $mail->Body = 'HTML message body in <b>bold</b> '; 
    $mail->AltBody = 'Body in plain text for non-HTML mail clients'; 
    $mail->send(); 
    echo "Mail has been sent successfully!"; 
} catch (Exception $e) { 
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; 
} 

?> 

【问题讨论】:

    标签: php smtp phpmailer


    【解决方案1】:

    您的 Gmail 可能存在身份验证问题。请确保您在连接到 Gmail 之前已完成以下步骤。

    # Visit https://accounts.google.com
    #
    # 1. Click on [Security] menu
    # 2. Scroll to section [Less secure app access] and set it to ON
    # 3. Scroll to section [Signing in to Google] and set [Use your phone to sign in] to OFF 
    # 4. Scroll to section [Signing in to Google] and set [2-step Verification] to OFF 
    #
    

    【讨论】:

    • 我尝试了你提到的所有方法,但它不起作用
    猜你喜欢
    • 2016-09-28
    • 2020-10-27
    • 2020-12-08
    • 1970-01-01
    • 2012-09-29
    • 2018-07-17
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多