經歷了phpmailer的所有步驟並查看了各種各樣的計算器。 測試了我可以從與我有同樣問題的人那裏找到的所有答案,但它對我無效。PHPMailer用smtp.gmail.com發送郵件時出錯
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 your web browser and 534-5.7.14 then try again
我已輸入正確的密碼Gmail帳戶,並編輯我的設置,以允許不太安全的應用程序。
一如既往,非常感謝用戶認真對待我。
'我輸入了一個有效的gmail';刪除這些評論,並把一些虛擬的ID和密碼。例如[email protected]和password =「******」; etc @CasualVictim –