使用PHPmailer如何修复:SMTP错误:无法进行身份验证。 SMTP错误:无法验证

时间:2018-02-24 18:41:15

标签: php smtp phpmailer

这篇文章是从最初的问题发展而来的,我在代码中复制了由于格式化而导致错误的问题。我现在正在努力解决一个新错误。初始问题已变为冗余问题。我会检查其他帖子是否有可能修复。我一直在关注如何使用PHPmailer和SMTP发送电子邮件的教程。我正在使用Xampp localhost。我已经使用composer安装了PHPmailer。我收到错误:SMTP错误:无法进行身份验证。 SMTP错误:无法进行身份验证。消息无法发送SMSTP错误:无法进行身份验证。

帮助将不胜感激。      

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

require_once 'vendor/autoload.php';

$m = new PHPMailer(true);


try{
$m->SMTPDebug = 2;
$m->isSMTP();
$m->Host = 'smtp.gmail.com';
$m->SMTPAuth = true;


$m->Username = 'munsonatl';
$m->Password = ' ';

$m->SMTPSecure = 'SSL';
$m->Port = 465;

$m->setFrom('munsonatl@gmail.com', 'Mailer');
$m->addAddress('munsonatl@gmail.com', 'Matt Macy');
$m->addReplyto('reply@mattmacy.com', 'replyAdress');


$m->Subject = "Here is an Email";
$m->Body = "This is the body of the email";
$m->AltBody = "This is the body of an email";
$m->send();
echo "message has been sent";

} catch (Exception $e){
echo "message could not be sent", $m->ErrorInfo;
}

&GT?; enter image description here

2 个答案:

答案 0 :(得分:1)

丢失括号或函数名后面的空格。

require_once ‘vendor/autoload.php’;

或者

require_once(‘vendor/autoload.php’);

答案 1 :(得分:0)

我发现帖子解决了我的问题。不得不在gmail中翻转一个开关:"SMTP Error: Could not authenticate" in PHPMailer

相关问题