SMTP错误:无法连接到服务器:拒绝(111)与Office365的连接 [英] SMTP ERROR: Failed to connect to server: Connection refused (111) with Office365

查看:38
本文介绍了SMTP错误:无法连接到服务器:拒绝(111)与Office365的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果这是一条人流很多的路。我看过其他关于这个问题的帖子,但它们既没有解决我的问题,也没有点燃一个灯泡来帮助我自己解决这个问题。

以下是我的代码:

require 'PHPMailerAutoload.php';
$config = parse_ini_file('/path/to/file/config.ini', true);
$mail = new PHPMailer;
$mail->SMTPDebug = 3;
$mail->Debugoutput = 'html';
$mail->isSMTP();
$mail->Host = $config['host']; //smtp.office365.com
$mail->SMTPAuth = true;
$mail->Username = $config['username']; //an.existing.account@appinc.co
$mail->Password = $config['password']; //confirmed this is being passed correctly
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = $config['username'];
$mail->FromName = 'Website Forms';
$mail->addAddress('sales@appinc.co', 'Some Name');
$mail->addReplyTo('sender.email@somedomain.com', 'SenderFirst SenderLast');
$mail->addBCC('my.email.address@appinc.co');
$mail->isHTML(true);
$mail->Subject = 'Contact Form Submission';
$mail->Body = 'Some html here';
$mail->AltBody = 'Some alt content here';
if(!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    //perform success actions
    exit();
}

我已确认域、用户名和密码都是正确的,并且传入正确。重要的是要注意,在启动之前,这在我们的本地开发服务器上有效。一旦网站被转移到我们的托管账户(Hostgator),就是它停止工作的时候。我已向HG确认我们的服务器上的端口587已打开。

以下是我看到的错误消息:

Connection: opening to smtp.office365.com:587, t=10, opt=array ()
SMTP ERROR: Failed to connect to server: Connection refused (111)
SMTP connect() failed.
Message could not be sent.Mailer Error: SMTP connect() failed.

非常感谢您能提供的任何帮助,即使它只是一篇文章的链接,该文章解释了为什么它现在在我们的生产环境中不起作用。

推荐答案

答案对我都不起作用。 几个小时后,我发现了问题,但只适用于Cpanel/WHM

  • 登录到WHM。
  • 转到ConfigServer Security Inside Firewall Inside插件选项(&A)。
  • 点击防火墙配置
  • 按SMTP设置筛选
  • 查找SMTP_ALLOWUSER选项并添加以COM分隔的Cpanel帐户的用户名
  • 重新启动防火墙。

如果您无权访问WHM,请咨询您的提供商。

这篇关于SMTP错误:无法连接到服务器:拒绝(111)与Office365的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆