PHPMailer:密码命令失败:534-5.7.14


PHPMailer: Password command failed: 534-5.7.14

function send_mail($message, $subject)
{
    if (array_key_exists('resume', $_FILES))
    {
        $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['resume']['name']));
        if (move_uploaded_file($_FILES['resume']['tmp_name'], $uploadfile))
        {
           require './PHPMailer/PHPMailerAutoload.php';
           $mail              = new PHPMailer;
           $mail->isSMTP();
           $mail->SMTPDebug   = 1;
           $mail->Debugoutput = 'html';
           $mail->Host        = 'smtp.gmail.com';
           $mail->Port        = 587;
           $mail->SMTPSecure = 'tls';            
           $mail->SMTPAuth    = true;
           $mail->Username    = "abc@gmail.com";
           $mail->Password    = "XXXX";
           $mail->SetFrom('abc@gmail.com', 'ABC');
           $mail->AddAddress('abc@gmail.com');
           $mail->Subject = $subject;
           $mail->MsgHTML($message);
           $mail->AltBody = 'This is a plain-text message body';
           $mail->addAttachment($uploadfile);
           if ($mail->Send())
           {
               echo "<script>alert('Your application is sent successfully. Our recruitment team will get in touch with you soon.');</script>";
           }
           else
           {
               echo "Mailer Error: " . $mail->ErrorInfo;
           }
       }
       else
       {
           echo 'Failed to move file to ' . $uploadfile;
       }
   }

}

我得到下面提到的错误:

CLIENT -> SERVER: EHLO localhost
CLIENT -> SERVER: STARTTLS
CLIENT -> SERVER: EHLO localhost
CLIENT -> SERVER: AUTH LOGIN
CLIENT -> SERVER: ZGV0ZWN0aW9uaW5zdHJ1bWVudEBnbWFpbC5jb20=
CLIENT -> SERVER: ZGV0ZWN0aW9uaW5kaWE=
SMTP ERROR: Password command failed: 534-5.7.14          <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbuk534-5.7.14 PHxasqAG-1Yi0Ij1bFvZdQIBCbXiwU2i-qOUAnhhTN-mHhCHRat1ivgXGVmBuQTk0cJTl2534-5.7.14 7kvt6yrXWWs9R8Rz1mxkje545Mg0F7Xx3Cl1VTW33gDBxGfcVfR-pIVPd1SIqMHWdICkLz534-5.7.14 pPL3_DNms_IS8jJkz3Eo3MH91Yq1OU3XUV1EXzfxaUA7xbYyK9jbwM1XVvVQ-NqqYYKCMY534-5.7.14 uNWA9kWIDl_XXYWrNNP6_cCiWomH8> Please log in via your web browser and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14 https://support.google.com/mail/answer/78754 bb5sm14055457pac.21 - gsmtp

SMTP 错误: 无法进行身份验证。客户端 -> 服务器:退出SMTP 连接(( 失败。https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting邮件程序错误: SMTP 连接(( 失败。

您可能需要

启用安全性较低的应用程序


更改安全性较低的应用的帐号访问权限

为了帮助确保 Google Apps 用户帐号的安全,我们可能会减少屏蔽 保护应用不让其访问 Google 企业应用套件帐号。作为谷歌应用程式 用户,您将在尝试签名时看到"密码不正确"错误 在。如果是这种情况,您有两种选择:

  1. 选项 1:升级到使用最新内容的更安全的应用 安全措施。所有谷歌产品,如Gmail,都使用最新的 安全措施。
  2. 方法 2:更改设置以允许安全性较低的应用访问 您的帐户。我们不建议使用此选项,因为它可能会使 有人更容易闯入您的帐户。如果你愿意 仍然允许访问,请按照以下步骤操作:

    2.1. 转到"我的帐户"中的"安全性较低的应用程序"部分

    2.2. 在"安全性较低的应用的访问权限"旁边,选择开启。(注意 Google Apps 用户:如果您的管理员锁定了安全性较低的应用帐号访问权限,此设置将被隐藏。

如果您仍然无法登录您的帐户,"密码 不正确"错误可能是由其他原因引起的。

SRC:https://support.google.com/accounts/answer/6010255?hl=en


注意:

打开 PHP 标记之后立即将错误报告添加到文件顶部,例如<?php error_reporting(E_ALL); ini_set('display_errors', 1);

并在 PHPMAILER 上启用调试

$mail->SMTPDebug  = 1; // enables SMTP debug information (for testing)
                       // 1 = errors and messages
                       // 2 = messages only

看看它是否产生任何东西。

我有同样的问题,但仅在尝试从 heroku 连接时。如果我尝试从 000webhost 连接,它适用于 ssl 或 tls...

我不想尝试使用应用程序密码策略(双因素身份验证(,但似乎没有其他方法可以尝试。