Email PHPMailer:似乎没有发送密码

Email PHPMailer:似乎没有发送密码,email,smtp,wamp,phpmailer,Email,Smtp,Wamp,Phpmailer,我检查了其他问题,但找不到与我的问题相匹配的问题。我正试图使用PHPMailer向我的电子邮件提供商(Pixel Internet)发送一封电子邮件,但身份验证失败。我使用与Thunderbird相同的主机名、用户名和密码,工作正常,因此我的代码中肯定有错误 这是我的代码: $mail->isSMTP(); $mail->Host = $mail_smtp_host; $mail->Port = 587; $mai

我检查了其他问题,但找不到与我的问题相匹配的问题。我正试图使用PHPMailer向我的电子邮件提供商(Pixel Internet)发送一封电子邮件,但身份验证失败。我使用与Thunderbird相同的主机名、用户名和密码,工作正常,因此我的代码中肯定有错误

这是我的代码:

        $mail->isSMTP();
        $mail->Host = $mail_smtp_host;
        $mail->Port = 587;
        $mail->SMTPAuth = true;
        $mail->AuthType = "PLAIN";
        $mail->SMTPSecure = 'tls';
        $mail->Username = $mail_auth_username;
        $mail->Password = $mail_auth_password; // (Password in plain text)
        $mail->SMTPDebug = 4;
        $mail->setFrom('(my email address)', 'Jeff Goodenough');
        $mail->addAddress(...);
        $mail->Subject = 'Test';
        $mail->Body = 'Testing.';
        $mail->send();
这是我得到的调试跟踪:

2021-03-04 10:29:43 Connection: opening to mail50.extendcp.co.uk:587, timeout=300, options=array()
2021-03-04 10:29:43 Connection: opened
2021-03-04 10:29:43 SMTP INBOUND: "220 mta1.hi.local ESMTP Exim 4.94 Thu, 04 Mar 2021 10:29:43 +0000"
2021-03-04 10:29:43 SERVER -> CLIENT: 220 mta1.hi.local ESMTP Exim 4.94 Thu, 04 Mar 2021 10:29:43 +0000
2021-03-04 10:29:43 CLIENT -> SERVER: EHLO localhost
2021-03-04 10:29:43 SMTP INBOUND: "250-mta1.hi.local Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]"
2021-03-04 10:29:43 SMTP INBOUND: "250-SIZE 52428800"
2021-03-04 10:29:43 SMTP INBOUND: "250-8BITMIME"
2021-03-04 10:29:43 SMTP INBOUND: "250-PIPELINING"
2021-03-04 10:29:43 SMTP INBOUND: "250-X_PIPE_CONNECT"
2021-03-04 10:29:43 SMTP INBOUND: "250-AUTH PLAIN LOGIN CRAM-MD5"
2021-03-04 10:29:43 SMTP INBOUND: "250-CHUNKING"
2021-03-04 10:29:43 SMTP INBOUND: "250-STARTTLS"
2021-03-04 10:29:43 SMTP INBOUND: "250 HELP"
2021-03-04 10:29:43 SERVER -> CLIENT: 250-mta1.hi.local Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]250-SIZE 52428800250-8BITMIME250-PIPELINING250-X_PIPE_CONNECT250-AUTH PLAIN LOGIN CRAM-MD5250-CHUNKING250-STARTTLS250 HELP
2021-03-04 10:29:43 CLIENT -> SERVER: STARTTLS
2021-03-04 10:29:43 SMTP INBOUND: "220 TLS go ahead"
2021-03-04 10:29:43 SERVER -> CLIENT: 220 TLS go ahead
2021-03-04 10:29:43 CLIENT -> SERVER: EHLO localhost
2021-03-04 10:29:44 SMTP INBOUND: "250-mta1.hi.local Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]"
2021-03-04 10:29:44 SMTP INBOUND: "250-SIZE 52428800"
2021-03-04 10:29:44 SMTP INBOUND: "250-8BITMIME"
2021-03-04 10:29:44 SMTP INBOUND: "250-PIPELINING"
2021-03-04 10:29:44 SMTP INBOUND: "250-X_PIPE_CONNECT"
2021-03-04 10:29:44 SMTP INBOUND: "250-AUTH PLAIN LOGIN CRAM-MD5"
2021-03-04 10:29:44 SMTP INBOUND: "250-CHUNKING"
2021-03-04 10:29:44 SMTP INBOUND: "250 HELP"
2021-03-04 10:29:44 SERVER -> CLIENT: 250-mta1.hi.local Hello host86-151-185-147.range86-151.btcentralplus.com [86.151.185.147]250-SIZE 52428800250-8BITMIME250-PIPELINING250-X_PIPE_CONNECT250-AUTH PLAIN LOGIN CRAM-MD5250-CHUNKING250 HELP
2021-03-04 10:29:44 Auth method requested: PLAIN
2021-03-04 10:29:44 Auth methods available on the server: PLAIN,LOGIN,CRAM-MD5
2021-03-04 10:29:44 CLIENT -> SERVER: AUTH PLAIN
2021-03-04 10:29:44 SMTP INBOUND: "535 Incorrect authentication data"
2021-03-04 10:29:44 SERVER -> CLIENT: 535 Incorrect authentication data
2021-03-04 10:29:44 SMTP ERROR: AUTH command failed: 535 Incorrect authentication data
SMTP Error: Could not authenticate.
2021-03-04 10:29:44 CLIENT -> SERVER: QUIT
2021-03-04 10:29:44 SMTP INBOUND: "221 mta1.hi.local closing connection"
2021-03-04 10:29:44 SERVER -> CLIENT: 221 mta1.hi.local closing connection
2021-03-04 10:29:44 Connection: closed
SMTP Error: Could not authenticate.
这是我的电子邮件提供商给出的一个示例(即他们期望的事情):

区别在于客户端到服务器的AUTH-PLAIN消息:我的调试跟踪只显示“AUTH-PLAIN”,而Pixel的示例显示了后面的编码字符串。我缺少什么?

提供了
AUTH PLAIN
SMTP身份验证机制的两个示例。第一种情况就像你看到的:

S: 250 AUTH GSSAPI DIGEST-MD5 PLAIN
C: AUTH PLAIN dGVzdAB0ZXN0ADEyMzQ=
S: 235 2.7.0 Authentication successful
第二种是同一机制的另一种形式:

S: 250 AUTH GSSAPI DIGEST-MD5 PLAIN
C: AUTH PLAIN
S: 334
C: dGVzdAB0ZXN0ADEyMzQ=
S: 235 2.7.0 Authentication successful
您可以看到,这两个方法提交了相同的身份验证字符串,但第二个方法在发送身份验证字符串之前,还有一个来自服务器的
334
响应。虽然这种方法的效率稍低,但其优点是该方法与类似的
登录
auth机制相同,该机制也使用了
334
中间响应

PHPMailer为
PLAIN
实现第二种机制。您的服务器显然不喜欢这样,我将其描述为一个bug;它应该允许两种模式

一个简单的解决方案是切换到使用服务器也支持的
登录
机制,并且只有一个版本:

$mail->AuthType = 'LOGIN';

您还可以使用
CRAM-MD5
,它由您的服务器和PHPMailer支持,并且稍微更安全,尽管通过TLS它没有多大区别。

。我发送到的服务器上的AUTH PLAIN协议有问题。我将auth类型更改为CRAM-MD5,一切正常。

谢谢Synchro-我在发布我的回复之前没有看到你的回复-我可能应该先刷新页面!我的结论(在查看了PHPMailer代码之后——特别是SMTP.php中的authenticate函数)与您在这里描述的内容基本相同。我切换到CRAM-MD5,服务器挑战按预期进行。我还没有尝试登录,尽管服务器报告它支持这三种功能。非常感谢您抽出时间回复。我会把你当作答案!
$mail->AuthType = 'LOGIN';