在完成phpmailer的所有步骤并查看stackoverflow之后。我从和我有同样问题的人那里找到了所有我能找到的答案,但它对我不起作用。
My code is simple:
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 1; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'I entered a valid gmail'; // SMTP username
$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;) )'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->From = 'The email its sent from';
$mail->FromName = 'Lobby desk';
$mail->addAddress(' Recipients mail '); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
我希望有人能指出我的代码有什么问题,为什么会出现这个错误:
SMTP connect() failed
:
SMTP ERROR: Password command failed: 534-5.7.14 Please log in via您的浏览器和534-5.7.14,然后再试一次
我已经输入了gmail帐户的正确密码,并编辑了我的设置,以允许不太安全的应用程序。
一如既往,提前感谢那些认真对待我的用户
请在您的gmail帐户设置中检查一次是否允许使用此帐户作为收件人。我想这可能就是问题所在。
本行问题
$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;) )';
^ ^^^ ^
改变
$mail->Password = "I entered my password(I'm not giving it to you people, I know what you can do ;) )";
使用Gmail和PHPMailer的基本示例