【问题标题】:SMTP connect() failed PHP mailerSMTP connect() 失败 PHP 邮件程序
【发布时间】:2015-07-02 04:47:12
【问题描述】:

我正在尝试使用 PHPMailer 从我的 hotmail 帐户发送电子邮件。它在我的电脑上运行良好,但是当我在另一台电脑上尝试时,我收到以下错误消息:

2015-04-23 17:31:18 客户端 -> 服务器:EHLO 本地主机
2015-04-23 17:31:18 客户端 -> 服务器:退出
2015-04-23 17:31:18 SMTP 连接()失败。邮件错误

这是我的代码:

<?php
require "C:\wamp\www\PHPMailer-master\PHPMailerAutoload.php";
    $mail = new PHPMailer();
    $mail->SMTPSecure = 'SSL';
    $mail->Username = "b1sakher@hotmail.fr";
    $mail->Password = "rerered";
    $mail->AddAddress("b1sakher@hotmail.fr");
    $mail->FromName = "My Name";
    $mail->Subject = "My Subject";
    $mail->Body = "My Body";
    $mail->Host = "smtp.live.com";
    $mail->Port = 587;
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->From = $mail->Username;
  if(!$mail->Send())
    {
     echo "Mailer Error";
    }
    else
     {
    echo "Message has been sent";
    }
?>

【问题讨论】:

  • 这台“另一台”PC 上的 587 端口是否打开?
  • SMTP error with PHPMailer 的可能重复项
  • 请在发布问题之前付出最微不足道的努力。这个问题之前已经被问过很多次了,并且在the PHPMailer troubleshooting docs中得到了广泛的讨论。
  • 您的代码也基于旧示例,因此您可能也在使用旧版本的 PHPMaielr。
  • @EadhunDi:Telnet/ping 远程 pc/server 上的端口,如果它应答,则它是打开的。

标签: php email smtp phpmailer hotmail


【解决方案1】:

首先你应该在你的代码中添加“调试模式”,这会告诉你哪里出错了。

$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->SMTPDebug = 2; //Alternative to above constant

我遇到了类似的问题,但发现是 Cpanel/WHM 中的 CFS 防火墙阻塞了端口。

  1. 登录 WHM。
  2. 转到 ConfigServer Security & Firewall inside plugins 选项。
  3. 点击防火墙配置。
  4. 按 SMTP 设置过滤。
  5. 查找 SMTP_ALLOWUSER 选项并添加以逗号分隔的 Cpanel 帐户用户名。
  6. 重启防火墙。

如果您无法访问 WHM,请咨询您的托管服务提供商。

【讨论】:

    猜你喜欢
    • 2013-09-01
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 2015-08-27
    • 1970-01-01
    相关资源
    最近更新 更多