2
我正在嘗試將測試電子郵件發送到mailtrap.io收件箱,但在打開調試時我不斷收到這些錯誤。以前,我收到一個用戶名命令失敗,直到我添加AuthType = Login。無法使用PHPMailer和Mailtrap發送郵件
2017-08-01 22:34:46 SERVER -> CLIENT: 220 mailtrap.io ESMTP ready
2017-08-01 22:34:46 CLIENT -> SERVER: EHLO localhost
2017-08-01 22:34:46 SERVER -> CLIENT: 250-mailtrap.io 250-SIZE 5242880 250-PIPELINING 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-AUTH PLAIN LOGIN CRAM-MD5 250 STARTTLS
2017-08-01 22:34:46 CLIENT -> SERVER: STARTTLS
2017-08-01 22:34:46 SERVER -> CLIENT: 220 2.0.0 Start TLS
2017-08-01 22:34:47 CLIENT -> SERVER: EHLO localhost
2017-08-01 22:34:47 SERVER -> CLIENT: 250-mailtrap.io 250-SIZE 5242880 250-PIPELINING 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250 AUTH PLAIN LOGIN CRAM-MD5
2017-08-01 22:34:47 CLIENT -> SERVER: AUTH LOGIN
2017-08-01 22:34:47 SERVER -> CLIENT: 334 xxxx
2017-08-01 22:34:47 CLIENT -> SERVER: xxxxxxxxxxx=
2017-08-01 22:34:47 SERVER -> CLIENT: 334 xxxxxxxxxxxx
2017-08-01 22:34:47 CLIENT -> SERVER:
2017-08-01 22:34:50 SERVER -> CLIENT: 535 5.7.0 Invalid login or password 2017-08-01 22:34:50 SMTP ERROR: Password command failed: 535 5.7.0 Invalid login or password
2017-08-01 22:34:50 SMTP Error: Could not authenticate.
2017-08-01 22:34:50 CLIENT -> SERVER: QUIT
2017-08-01 22:34:51 SERVER -> CLIENT: 221 2.0.0 Bye
2017-08-01 22:34:51 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
這是我在嘗試發送電子郵件的頁面上的代碼。憑證存儲在Config類中,並且我已多次驗證用戶名和密碼與郵箱收件箱提供的用戶名和密碼相匹配。目前該端口設置爲465.我也嘗試過2525以達到相同的結果。端口25只會使申請超時。
if(isMethod('post')) {
if (isset($_POST['email'])) {
/*********************
*configure PHPMailer*
*********************/
$mail = new PHPMailer();
$mail->AuthType = 'LOGIN';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = Config::SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = Config::SMTP_USER;
$mail->Passowrd = Config::SMTP_PASSWORD;
$mail->SMTPSecure = 'tls';
$mail->Port = Config::SMTP_PORT;
$mail->isHTML(true);
$mail->setFrom('[email protected]', 'My Name');
if (!getEmailDb()) {
echo (displayMessage("E-Mail does not exist.", "warning"));
}
else {
$email = getEmailDb();
$token = bin2hex(openssl_random_pseudo_bytes(50));
$mail->addAddress($email);
$mail->Subject = 'This is a test email.';
$mail->Body = 'Email body';
if($mail->send()) {
echo (displayMessage("E-Mail sent. It should show up in your inbox pretty soon.", "success"));
}
else {
echo (displayMessage("Could not send E-Mail to ".$email, "warning"));
}
}
}
}
設置'$ mail-> SMTPDebug = 2;'這樣你就可以看到服務器在說什麼了。 TLS將無法工作到端口465;嘗試587.另外,請閱讀錯誤消息指出的故障排除指南。 – Synchro
使用該端口會導致超時。 Mailtrap說爲SMTP連接使用25,465或2525。我將在端口465下編輯這個帖子並提供調試級別2的信息。 – SolidSnackDrive
也許[this](https://stackoverflow.com/a/25670661/2917673)可以幫助 – Yolo