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 PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
$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>

您需要在 Gmail 帐户设置中为安全性较低的应用程序启用访问权限,才能从 PHP 脚本发送电子邮件。

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

最新更新