【问题标题】:SMTP: Failed to connect socket: Connection RefusedSMTP:无法连接套接字:连接被拒绝
【发布时间】:2012-06-28 00:48:52
【问题描述】:

我正在尝试使用 PEAR 邮件包和 SMTP 在 PHP 中发送电子邮件,但我不断收到错误 SMTP: Failed to connect socket: Connection Refused

我对 SMTP 的工作原理一无所知,请耐心等待。

这是我的代码:

$recipients = $_SESSION['email'];
$headers["From"] = "example@example.com";
$headers["To"] = "example@example.com";
$headers["Subject"] = 'Subject Text!';
$mailmsg = $_SESSION['body'];

/* SMTP server name, port, user/password */
$smtpinfo["host"] = "mail.example.com";
$smtpinfo["port"] = "587";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = $email_user;
$smtpinfo["password"] = $email_pass;
/* Create the mail object using the Mail::factory method */
$mail_object =& Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$send = $mail_object->send($recipients, $headers, $mailmsg);
if (PEAR::isError($send)) {
    echo '<p>Error: ' . $send->getMessage() . '</p>';
} else {
    header('Location: ../../emailed.php');
}

我所知道的是:

域是 hostgator,电子邮件处理程序是 Keiro Connect。

我不确定要通过哪个端口。我查看了服务,它说侦听 IP 地址是:

  • SMTP:所有地址:25,所有地址:587
  • 安全 SMTP:所有地址:465
  • SMTP 提交:所有地址:587 *此服务已关闭

我还注意到 SMTP 传送设置为直接使用 DNS MX 记录传送。我不知道这是否意味着什么。

我做错了什么?我应该寻找什么才能按顺序获取所有参数? 任何帮助将不胜感激。

【问题讨论】:

  • 这更多是服务器问题而不是编码问题。远程主机正在阻止连接。 ServerFault 可能会更好地提供服务

标签: php email smtp pear


【解决方案1】:

仅仅因为您正在侦听端口并不意味着您可以访问它。系统或上游内联设备上的防火墙可能会阻止它。

在您运行脚本的本地计算机上,执行telnet mail.example.com 587,您是否会收到提示?

【讨论】:

  • 提示是:Trying: XXX.XX.X.XXX... 连接到waiter.example.com。转义字符是 '^]'。 220 waiter.example.com Kerio Connect 7.4.1 ESMTP 就绪
  • 好的,太好了!这意味着您可以建立与服务器的连接。接下来,$email_user 是否包含@domain.com?
  • 不,只是@domain.com 之前的用户名
【解决方案2】:

我以前遇到过这样的问题.. 并且花费了我的时间来解决...
也可以在服务器上尝试您的脚本.. 有时对于某些 SMTP 主机,您无法从本地计算机发送电子邮件。
我添加答案(或建议)为时已晚。但它可能对某人有所帮助..

【讨论】:

    【解决方案3】:

    如果您没有 ssl 认证,我建议使用端口 25。获得 ssl 后,我会将端口配置更改为 465。您为什么使用该端口号?我认为它不符合hostgator。 从 hostgator 查看此网页。 http://support.hostgator.com/articles/email-connection-settings

    【讨论】:

      猜你喜欢
      • 2011-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多