535 5.7.8 错误:在 Hostinger 上使用 PHPMailer 身份验证失败,用户和密码正确

问题描述 投票:0回答:1

我一直在尝试使用 PHPMailer 为我的网站创建联系表单,因为它似乎是我想要做的事情的最简单的选择。我在 Hostinger 上托管我的网站,并使用他们的“Titan Mail”发送电子邮件。我对 PHP 很陌生,并且总体上处理后端问题,所以我不太确定下一步该去哪里。

Hostinger 的帮助文章说我应该使用此代码发送测试电子邮件以确保其有效:

<?php
   require 'vendor/autoload.php';
   use PHPMailer\PHPMailer\PHPMailer;
   $mail = new PHPMailer;
   $mail->isSMTP();
   $mail->SMTPDebug = 2;
   $mail->Host = 'smtp.hostinger.com';
   $mail->Port = 587;
   $mail->SMTPAuth = true;
   $mail->Username = '[email protected]';
   $mail->Password = 'My$tr0ngPa55w0rd!';
   $mail->setFrom('[email protected]', 'Your Name');
   $mail->addReplyTo('[email protected]', 'Your Name');
   $mail->addAddress('[email protected]', 'Receiver Name');
   $mail->Subject = 'Checking if PHPMailer works';
   $mail->msgHTML(file_get_contents('message.html'), __DIR__);
   $mail->Body = 'This is just a plain text message body';
   //$mail->addAttachment('attachment.txt');
   if (!$mail->send()) {
       echo 'Mailer Error: ' . $mail->ErrorInfo;
   } else {
       echo 'The email message was sent.';
   }
?>

这不起作用,我也尝试使用主机作为“smtp.titan.email”,但没有成功。我输入了我的用户名和密码等,但是当我运行脚本时它会抛出此错误:

2024-07-08 14:28:21 SERVER -> CLIENT: 220 smtp-out.flockmail.com ESMTP Postfix
2024-07-08 14:28:21 CLIENT -> SERVER: EHLO {MY-DOMAIN-NAME}
2024-07-08 14:28:21 SERVER -> CLIENT: 250-smtp-out.flockmail.com250-PIPELINING250-SIZE 52428800250-VRFY250-ETRN250-STARTTLS250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
2024-07-08 14:28:21 CLIENT -> SERVER: STARTTLS
2024-07-08 14:28:21 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2024-07-08 14:28:21 CLIENT -> SERVER: EHLO {MY-DOMAIN-NAME}
2024-07-08 14:28:21 SERVER -> CLIENT: 250-smtp-out.flockmail.com250-PIPELINING250-SIZE 52428800250-VRFY250-ETRN250-AUTH PLAIN LOGIN250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250 CHUNKING
2024-07-08 14:28:21 CLIENT -> SERVER: AUTH LOGIN
2024-07-08 14:28:21 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2024-07-08 14:28:21 CLIENT -> SERVER: [credentials hidden]
2024-07-08 14:28:21 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2024-07-08 14:28:21 CLIENT -> SERVER: [credentials hidden]
2024-07-08 14:28:23 SERVER -> CLIENT: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
2024-07-08 14:28:23 SMTP ERROR: Password command failed: 535 5.7.8 Error: authentication failed: UGFzc3dvcmQ6
SMTP Error: Could not authenticate.
2024-07-08 14:28:23 CLIENT -> SERVER: QUIT
2024-07-08 14:28:23 SERVER -> CLIENT: 221 2.0.0 Bye
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

我用谷歌搜索了错误代码并查看了几乎每个结果,人们说凭据不正确,但事实并非如此(据我所知)。我尝试将端口更改为 465,不同的主机名,但没有成功。关于出了什么问题有什么想法吗?

php smtp phpmailer hostinger
1个回答
0
投票

Titan Mail 的 SMTP 设置(由 Hostinger 提供)应如下所示:

SMTP 服务器:smtp.titan.email SMTP 端口:TLS 为 587 或 SSL 为 465

© www.soinside.com 2019 - 2024. All rights reserved.