我真的希望你們中的一個人可以幫助我。我一直用這個拉着我的頭髮約2個小時。我的客戶電子郵件服務器上的其中一個帳戶遭到入侵,Google開始阻止我們發送電子郵件的企圖。所以我試圖從基本的PHP郵件命令切換到PHPMailer並通過Google的SMTP服務器發送。此客戶使用Google專業版的所有帳戶。PHP郵件與PHPMailer通過谷歌SMTP
我使用了以下內容:
$mail = new PHPMailer();
$mail->isSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "tls"; // sets the prefix to the server
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "*********"; // GMAIL password
$mail->SetFrom('[email protected]', 'Jimmy');
$mail->Subject = $this->subject;
$body = $this->message;
//$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail->AddAddress($this->to, 'bob');
if(!$mail->Send()) {
error_log("Mailer Error: " . $mail->ErrorInfo);
echo '[br /]Fail';
} else {
error_log("Message sent!");
echo '[br /]Pass';
}
我知道證書是正確的,因爲我可以與他們登錄。我已經做了所有種類的東西這個腳本,它正試圖使用的帳戶發送:從TLS
- 更改到SSL
- '疏通Captcha驗證碼的帳戶
- 禁用2因素身份驗證(它已經關閉)
- 啓用「不夠安全的應用」
我不知道還能做什麼。這是我不斷收到的錯誤:
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: STARTTLS
2017-05-15 03:12:30 CLIENT -> SERVER: EHLO americanbeautytools.com
2017-05-15 03:12:30 CLIENT -> SERVER: AUTH LOGIN
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:30 CLIENT -> SERVER: xxx=
2017-05-15 03:12:32 SMTP ERROR: Password command failed: 535 Incorrect authentication data
2017-05-15 03:12:32 SMTP Error: Could not authenticate.
2017-05-15 03:12:32 CLIENT -> SERVER: QUIT
2017-05-15 03:12:32 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
有關密碼命令失敗的部分是我沒有得到的部分。當我用這個電子郵件帳戶登錄時,這怎麼會是錯誤的?
我已經看了大約15個關於這個主題的話題,而他們的建議都沒有解決我的問題。這是一個谷歌專家帳戶,我的客戶通過谷歌運行,所以它不會是'免費'限制的事情。
差不多*你發現,*和*排除指南這些線程中的每一個*,會告訴你**設置'SMTPDebug = 2' **。當它設置爲1時,你不會看到服務器說的任何東西。 – Synchro
如果您將代碼基於PHPMailer提供的gmail示例,那麼首先您就不會陷入這個難題。 – Synchro
@Synchro - 我確實已將它設置爲2,並且沒有提供任何其他有用的信息。你的第二條評論沒有幫助。我有我的代碼鏡像PHPMailer的例子,它的許多變化和錯誤仍然存在。我完成了這個設置。我正在切換到外部郵件提供商。 –