完成了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()失败
和
SMTP错误:密码命令失败:534-5.7.14请通过登录 您的网络浏览器和534-5.7.14然后再试一次
我输入了gmail帐户的正确密码并编辑了我的设置以允许安全性较低的应用。
一如既往,非常感谢让我认真对待的用户。
答案 0 :(得分:2)
请在您的Gmail帐户设置中查看一次,以获取使用此帐户作为邮件程序的权限。我认为这可能是个问题。
答案 1 :(得分:0)
这一行的问题
$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 ;) )";