我尝试使用SMTP进行连接,但失败了。这是我的代码。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
$mail->SMTPDebug = 20;
$mail->isSMTP();
$mail->Host = 'smtp.mail.yahoo.com';
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = 'david_thedragonzzz@yahoo.com';
$mail->Password = 'secret';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('david_thedragonzzz@yahoo.com', 'Mailer');
$mail->addAddress('david_thedragonzzz@yahoo.com', 'User');
$mail->addReplyTo('test@yahoo.com', 'Information');
$mail->isHTML(true);
$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';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
结果
2018-02-07 10:45:43 Connection: opening to ssl://smtp.mail.yahoo.com:465, timeout=300, options=array()
2018-02-07 10:45:43 Connection: opened
2018-02-07 10:45:43 SMTP INBOUND: "220 smtp.mail.yahoo.com ESMTP ready"
2018-02-07 10:45:43 SERVER -> CLIENT: 220 smtp.mail.yahoo.com ESMTP ready
2018-02-07 10:45:43 CLIENT -> SERVER: EHLO localhost
2018-02-07 10:45:43 SMTP INBOUND: "250-smtp.mail.yahoo.com"
2018-02-07 10:45:43 SMTP INBOUND: "250-PIPELINING"
2018-02-07 10:45:43 SMTP INBOUND: "250-SIZE 41697280"
2018-02-07 10:45:43 SMTP INBOUND: "250-8 BITMIME"
2018-02-07 10:45:43 SMTP INBOUND: "250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE OAUTHBEARER"
2018-02-07 10:45:43 SERVER -> CLIENT: 250-smtp.mail.yahoo.com250-PIPELINING250-SIZE 41697280250-8 BITMIME250 AUTH PLAIN LOGIN XOAUTH2 XYMCOOKIE OAUTHBEARER
2018-02-07 10:45:43 Auth method requested: LOGIN
2018-02-07 10:45:43 Auth methods available on the server: PLAIN,LOGIN,XOAUTH2,XYMCOOKIE,OAUTHBEARER
2018-02-07 10:45:43 CLIENT -> SERVER: AUTH LOGIN
2018-02-07 10:45:43 SMTP INBOUND: "334 VXNlcm5hbWU6"
2018-02-07 10:45:43 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-02-07 10:45:43 CLIENT -> SERVER: xxx==
2018-02-07 10:45:43 SMTP INBOUND: "334 UGFzc3dvcmQ6"
2018-02-07 10:45:43 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-02-07 10:45:43 CLIENT -> SERVER: xxx==
2018-02-07 10:45:46 SMTP INBOUND: "535 5.7.0 (#MBR1212) Incorrect username or password."
2018-02-07 10:45:46 SERVER -> CLIENT: 535 5.7.0 (#MBR1212) Incorrect username or password.
2018-02-07 10:45:46 SMTP ERROR: Password command failed: 535 5.7.0 (#MBR1212) Incorrect username or password.
SMTP Error: Could not authenticate.
2018-02-07 10:45:46 CLIENT -> SERVER: QUIT
2018-02-07 10:45:46 SMTP INBOUND: "221 2.0.0 Bye"
2018-02-07 10:45:46 SERVER -> CLIENT: 221 2.0.0 Bye
2018-02-07 10:45:46 Connection: closed
SMTP Error: Could not authenticate.
Message could not be sent. Mailer Error: SMTP Error: Could not authenticate.
我无法理解这段代码为何会给我带来错误的用户名或密码&#34;错误。我使用Mozilla Thunderbird配置了smtp。用户名和密码是正确的,但仍然给我这种错误。