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

如何解决Hostinger环境下PHPMailer的Password命令失败问题?

Hostinger下PHPMailer SMTP 535认证失败问题排查与解决

针对你遇到的535 5.7.8 Error: authentication failed错误,结合Hostinger主机特性,以下是实用的排查和解决步骤:

  • 确认SMTP凭证准确性
    Hostinger的SMTP用户名必须是完整的域名邮箱(如no-reply@yourdomain.tld),密码为该邮箱的登录密码。务必检查:

    • 密码是否存在大小写、特殊字符输入错误,复制时是否带了首尾空格
    • 若密码为Hostinger自动生成,确保特殊字符(如$、\)在代码中未被PHP错误解析
  • 检查Hostinger邮箱的SMTP权限
    登录Hostinger hPanel,进入Email > Email Accounts,选中对应邮箱账号:

    • 确认SMTP服务已启用(新创建邮箱默认启用,可手动验证)
    • 查看账号是否因多次错误登录被临时锁定,若锁定需解锁并重置密码
  • 验证SMTP配置参数
    Hostinger官方提供两组SMTP参数,可切换测试:

    1. TLS配置(你当前使用的):
      • Host: smtp.hostinger.com
      • Port: 587
      • SMTPSecure: 'tls'
    2. SSL配置(若TLS端口存在防火墙限制):
      • Host: smtp.hostinger.com
      • Port: 465
      • SMTPSecure: 'ssl'
  • 修正代码中的密码解析问题
    若密码包含特殊字符,PHP双引号字符串会自动解析变量或转义符,导致密码失效。建议用单引号包裹密码:

    $mail->Password = 'your_actual_password'; // 替换为真实邮箱密码
    
  • 排查服务器安全规则
    联系Hostinger客服确认:

    • 服务器是否允许587/465端口的出站SMTP连接
    • 你的IP是否被列入临时黑名单或触发安全防护规则

调整后的示例代码(SSL配置)

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/PHPMailer/src/Exception.php';
require 'PHPMailer/PHPMailer/src/PHPMailer.php';
require 'PHPMailer/PHPMailer/src/SMTP.php';

$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = 2;
    $mail->isSMTP();
    $mail->Host       = 'smtp.hostinger.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'no-reply@example.com'; // 替换为你的Hostinger域名邮箱
    $mail->Password   = 'your_actual_password'; // 用单引号包裹真实密码
    $mail->SMTPSecure = 'ssl';
    $mail->Port       = 465;

    //Recipients
    $mail->setFrom('no-reply@example.com', 'Mailer');
    $mail->addAddress('myemail@gmail.com', 'John Doe');

    // Content
    $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}";
}
?>

内容的提问来源于stack exchange,提问作者Justin Buzek

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 07:27:21