You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hostinger平台使用PHPMailer遭遇535 5.7.8认证失败问题求助

问题描述

我正在为网站开发联系表单,用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.titan.email';
   $mail->Port = 587;
   $mail->SMTPAuth = true;
   $mail->Username = 'mymail@myawesomedomain.tld';
   $mail->Password = 'My$tr0ngPa55w0rd!';
   $mail->setFrom('mymail@myawesomedomain.tld', 'Your Name');
   $mail->addReplyTo('mymail@myawesomedomain.tld', 'Your Name');
   $mail->addAddress('recipient@domain.tld', '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.';
   }
?>

测试未成功,尝试将Host改为smtp.hostinger.com也无效。确认账号及密码填写正确,但运行脚本时出现以下错误:

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、更换Host地址,均未解决问题,请问可能是什么原因导致的?

可能的原因及解决方法
  • 密码特殊字符解析问题:你的密码包含$这类PHP特殊字符,即使代码里用了单引号,也可能因环境差异出现解析异常。建议手动重新输入密码,或者将密码转义后再赋值,比如用addslashes()处理后传入。
  • 缺少SMTP加密配置:代码里未明确设置SMTPSecure参数,Titan Mail要求对应端口启用加密:
    • 端口587时,添加$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    • 端口465时,添加$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
  • Titan Mail账号权限限制:检查Hostinger后台的Titan Mail设置,确认该账号是否启用了SMTP发送权限,部分套餐可能默认关闭此功能,或者需要单独开启。
  • Hostinger平台的SMTP限制:Hostinger可能对外部SMTP调用有拦截,尝试改用Hostinger自带的邮件发送方式测试,比如直接使用PHP原生mail()函数,排除平台层面的限制。
  • 密码存在不可见字符:复制粘贴密码时可能带入空格、换行等不可见字符,建议手动逐字符输入密码,避免此类问题。
  • 应用专用密码需求:如果你的Titan Mail账号开启了双重验证,需要生成应用专用密码替代原密码用于SMTP验证,而非直接使用账号登录密码。

内容的提问来源于stack exchange,提问作者Charlie Rundquist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 12:37:06