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

时间:2018-04-19 10:08:42

标签: php phpmailer cpanel

我是 PHPMailer 的新手,我刚刚使用 Composer 下载并将其编码为index.php

    <?php 
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
$m = new PHPMailer;
$m->isSMTP();
$m->SMTPAuth = true;
$m->SMTPDebug = 2;

$m->Host = 'smtp.mail.yahoo.com';
$m->Username = 'vagefipooya@yahoo.com';
$m->Password = 'MY PASSWORD';
$m->SMTPSecure = 'ssl';
$m->Port = 465;
$m->IsHTML(true);

$m->SetFrom('pouyavey@gmail.com');
$m->FromName = 'Pouya Vaghefi';
$m->addReplyTo('pouyavey@gmail.com','Pouya Vey');
$m->addAddress('pouyavey@gmail.com','Pouya Vey');
//$m->addCC('alex@phpacademy','Alex Garret');
//$m->addBCC('alex@phpacademy','Alex Garret');
$m->CharSet = "UTF-8";

$m->Subject = 'Here is an email';
$m->msgHTML("convert HTML into a basic plain-text alternative body");
$m->Body = 'This is the body of an email';
$m->AltBody = 'This is the body of an email';

if (!$m->send()) {
        echo "Mailer Error: " . $m->ErrorInfo;
    } else {
        echo "Message sent!";
    }
    ?>

然后我将它上传到我的网站(我的网站不使用ssl),这是使用 cPanel 并尝试加载页面但我得到了这个错误:

  

2018-04-19 10:03:46 SMTP错误:无法连接到服务器:连接被拒绝(111)   SMTP connect()失败。 /维基/故障排除   邮件程序错误:SMTP连接()失败。

我还阅读了与此问题相关的问题,并将端口从465更改为587(使用tls),25和26,但尚无法解决问题。

所以,请你帮我解决这个错误,因为我真的不知道该怎么做!

...谢谢

3 个答案:

答案 0 :(得分:6)

这主要是由于您的托管服务提供商防火墙问题。请参阅以下链接,其中有人有类似的问题 -

https://github.com/PHPMailer/PHPMailer/issues/295

联系您的托管服务提供商,他们将能够为您提供帮助

答案 1 :(得分:2)

我使用我的电子邮件和令牌尝试了您的代码,也没有用,它显示:

2018-04-28 13:52:41     SMTP ERROR: Failed to connect to server:  (0)
2018-04-28 13:52:41     SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

然后我改为两行:

$m->SMTPSecure = 'ssl';
$m->Port = 465;

$m->SMTPSecure = 'tls';
$m->Port = 587;

然后,它的工作原理

    ...
2018-04-28 13:53:13     SERVER -> CLIENT: 354 Start mail input; end with <CRLF>.<CRLF>
2018-04-28 13:53:13     CLIENT -> SERVER: Date: Sat, 28 Apr 2018 21:53:04 +0800
2018-04-28 13:53:13     CLIENT -> SERVER: To: "feiffy" <example@example.com>
2018-04-28 13:53:13     CLIENT -> SERVER: From: feiffy <feifeifanye@hotmail.com>
2018-04-28 13:53:13     CLIENT -> SERVER: Reply-To: "feiffy" <example@example.com>
2018-04-28 13:53:13     CLIENT -> SERVER: Subject: Here is an email
2018-04-28 13:53:13     CLIENT -> SERVER: Message-ID: <hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o@pc>
2018-04-28 13:53:13     CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
2018-04-28 13:53:13     CLIENT -> SERVER: MIME-Version: 1.0
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: multipart/alternative;
2018-04-28 13:53:13     CLIENT -> SERVER:       boundary="b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o"
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is a multi-part message in MIME format.
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is the body of an email
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o
2018-04-28 13:53:13     CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: This is the body of an email
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: --b1_hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o--
2018-04-28 13:53:13     CLIENT -> SERVER:
2018-04-28 13:53:13     CLIENT -> SERVER: .
2018-04-28 13:53:14     SERVER -> CLIENT: 250 2.0.0 OK <hW4npgJlHQ2CjCqR42xK7j7BRpAzEFAz8mnwK4G6o@pc> [Hostname=SG2PR06MB0776.apcprd06.prod.outlook.com]
2018-04-28 13:53:14     CLIENT -> SERVER: QUIT
2018-04-28 13:53:14     SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
希望能帮到你。

答案 2 :(得分:0)

我一直在使用mailgun,我喜欢它。 Mailgun.com对于这样的案件完全免费。

作为一个建议,你能看看你的盒子上是否有一个sendmail守护进程?也许这对你的用例来说足够好了吗?

相关问题