PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝 (111)

标签 php email smtp phpmailer

我遇到了一个奇怪的问题。我正在尝试使用 PHPMailer 通过 SMTP 发送电子邮件。我有一个由 GoDaddy 托管的网站,我正尝试使用该 SMTP 帐户发送邮件。

  1. 如果我在我的本地主机服务器上执行我的 PHP 文件,它就会工作。
  2. 如果我在 GoDaddy 的服务器上执行我的 PHP 文件,它不起作用。

我得到的错误信息是:

SMTP -> 错误:无法连接到服务器:连接被拒绝 (111)

我检查了本地主机和远程服务器上的 phpinfo。两者都将 smtp_port 列为 25。我在我的机器上使用 WAMP,服务器是某种形式的 Linux(我对此一无所知,也不知道如何管理)。

这里是有问题的代码:

INDEX.PHP:

<?php
date_default_timezone_set('America/Los_Angeles');
include_once("phpmailer/class.phpmailer.php");

$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->Port = 25;

$mail->IsSMTP();
$mail->Host = 'smtpout.secureserver.net';
$mail->SMTPAuth = true;
$mail->Username = 'username@site.com';
$mail->Password = 'super_secret_password';
$mail->SMTPSecure = ''; // tried ssl and tls, with same result

$mail->ClearAddresses();
$mail->AddAddress('receiver@hotmail.com', 'Receiver Name');
$mail->From = "username@site.com";
$mail->FromName = "Username";
$mail->Subject = 'Hi there';
$mail->Body = "This is a message";

if ($mail->Send()) {
    echo "Message sent!\n";
}
else {
    echo "Message failed!\n";
    print_r($mail->ErrorInfo);
}

exit();
?>

最佳答案

我认为你应该执行两个步骤 1) 按照 godaddy 支持 http://support.godaddy.com/help/article/319/what-do-i-do-if-i-have-trouble-connecting-to-my-email-account 上的建议检查您的端口 2)使用“relay-hosting.secureserver.net”作为你的主机而不是“smtpout.secureserver.net”

GoDaddy 确实允许使用 Gmail 作为您的 SMTP 发送电子邮件,只需要摆脱 smtp.gmail.com 并改用他们的主机。这是我的设置:

$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "relay-hosting.secureserver.net";
$mail->Username = "your-account@gmail.com";
$mail->Password = "yourpassword";
// ...
// send from, send to, body, etc...

引用(见前两篇文章)http://support.godaddy.com/groups/web-hosting/forum/topic/phpmailer-with-godaddy-smtp-email-server-script-working/

关于PHPMailer:使用远程 SMTP 服务器,在本地主机下工作,远程服务器上的连接被拒绝 (111),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21668488/

相关文章:

perl - 当我尝试使用 MIME::Lite 向 Gmail 帐户发送电子邮件时,为什么会收到 "SMTP Failed to connect to mail server:"?

SMTP 错误代码合规性

php - 根据条件从数据库中的 2 个表中选择数据 CakePHP

javascript - 如何计算给定时间超过 24 小时的时间百分比 hh :mm:ss?

node.js - hapijs joi 电子邮件验证选项 tldWhitelist 用法

java - 使用java从PC发送短信到手机

PHP PDO 不插入新记录

php - mysql,使用 "where"中的条件

c# - 在 C# 中使用 ProtonMail 发送电子邮件

c# - IIS SMTP : Exceeded storage allocation response