PHPMailer错误(无法进行身份验证。)

时间:2018-05-16 13:23:49

标签: php phpmailer

我正在尝试使用PHPMalier发送电子邮件。但它显示我的错误。我确信我的电子邮件和我的密码是正确的。我尝试了Youtube,Google甚至StackOverflow上的所有解决方案,但没有任何帮助。 PHP对我来说有点新鲜,所以我不太了解PHP。

这是主要的错误

SMTP ERROR: Password command failed: 
Please log in via your web browser  
SMTP Error: Could not authenticate.
 2018-05-16 13:11:10 CLIENT -> SERVER: QUIT
   2018-05-16 13:11:10 SERVER -> CLIENT: 221 2.0.0 closing connection i1- 
   v6sm5130251pfi.133 - gsmtp
  SMTP Error: Could not authenticate.
  Email Error.INFO:SMTP Error: Could not authenticate.

这是我的代码

<!DOCTYPE html>
 <html>
 <head>
 <title></title>
</head>
<body>
 <?php

 require "vendor/autoload.php";

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

$developmentMode = true;
$mailer = new PHPMailer($developmentMode);

 try {
  $mailer->SMTPDebug = 2;
$mailer->isSTMP();


 if ($developmentMode) {

         $mailer->SMTPOptions = [
           'ssl'=> [
              'verify_peer' => false,
           'verify_peer_name' => false,
          'allow_self_signed' => true
        ]
     ];

    } 

    $mailer->Host = 'smtp.gmail.com';
      $mailer->SMTPAuth = true;
    $mailer->Username = "mygmail@gmail.com";
    $mailer->Password = "password";
      $mailer->SMTPSecure = 'tls';
    $mailer->Port = 587;

      $mailer-> setFrom("mygmail@gmail.com", "Izaya");
      $mailer->addAddress("anothergmail@gmail.com","orihara");

    $mailer->isHTML(true);
     $mailer->Subject = "Hey There";
    $mailer->Body = "NICE TO MEET YOU IZAYA ";


   $mailer->send();
  $mailer->ClearAllRecipients();
   echo "Mail has been Sent";



      }catch (Exception $e) {
 echo "Email Error.INFO:" . $mailer->ErrorInfo;

  }


 ?>
 </body>
 </html>

1 个答案:

答案 0 :(得分:0)

您需要为gmail帐户设置中不太安全的应用启用访问权限才能从PHP脚本发送电子邮件。

您可以参考此Google文档页面了解如何启用它: https://support.google.com/accounts/answer/6010255?hl=en

相关问题