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