douyuanliao8815 2015-05-12 21:48
浏览 578
已采纳

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

Im using phpmailer to send emails using google business apps. Everything was running fine but since last three days, I've started to get the following error

SMTP -> ERROR: Failed to connect to server: Connection refused (111)
The following From address failed: example@example.com 

The strange thing is that, this doesn't happen all the time. For example, Out of 10 emails, I get the above error for 9 and 1 email sometimes is sent out to recipient.

Here is my code

<?php

function sendmail($mail_to,$mail_sub,$mail_mesg){

//mail("casper.kotwal@gmail.com", "LRD sendmail", "inside send mail");

require_once('classes/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug  = 2;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = "ssl";
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;
$mail->Username   = "example@example.com";
$mail->Password   = "example";
$mail->AddReplyTo('example@example.com', 'Example Documents');
$mail->AddAddress($mail_to);
$mail->SetFrom('example@example.com', 'Example Documents');
$mail->Subject = $mail_sub;
$mail->MsgHTML($mail_mesg);
$mail->Send();
}

sendmail("casper.kotwal@gmail.com", "test", "test");

EDIT I've updated my phpmailer to 5.2 (latest) but still I get this same error. The worst thing is sometimes it works and sometimes it doesn't. I've checked both ports for tls and ssl, both are listening fine.

Here is what I've done so far

  1. Updated PHPMailer to latest version
  2. Tried both tls on 587 and ssl on 465
  3. Verified that both ports are listening
  4. tried to connect to smtp.gmail.com through telnet using both ports (ssl and tls)
  5. Tested all three different email addresses of google apps (a@a.com, b@b.com, c@c.com). All sites are giving same error - SMTP ERROR: Failed to connect to server: Connection refused (111)
  6. Tested my code on different VPS and it "looks" to run fine over there.

Here is the output of debug when email is sent

SERVER -> CLIENT: 220 mx.google.com ESMTP df1sm6922498wib.12 - gsmtp
CLIENT -> SERVER: EHLO www.land-registry-documents.co.uk
SERVER -> CLIENT: 250-mx.google.com at your service, [2001:41c8:51:609:fcff:ff:fe00:3b86]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO www.land-registry-documents.co.uk
SERVER -> CLIENT: 250-mx.google.com at your service, [2001:41c8:51:609:fcff:ff:fe00:3b86]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 334 VXNlcm5hbWU6
CLIENT -> SERVER: c3lzdGVtQGxhbmQtcmVnaXN0cnktZG9jdW1lbnRzLmNvLnVr
SERVER -> CLIENT: 334 UGFzc3dvcmQ6
CLIENT -> SERVER: bmV3Y2FzdGxlbGVlZHM=
SERVER -> CLIENT: 235 2.7.0 Accepted
CLIENT -> SERVER: MAIL FROM:<system@land-registry-documents.co.uk>
SERVER -> CLIENT: 250 2.1.0 OK df1sm6922498wib.12 - gsmtp
CLIENT -> SERVER: RCPT TO:<casper.kotwal@gmail.com>
SERVER -> CLIENT: 250 2.1.5 OK df1sm6922498wib.12 - gsmtp
CLIENT -> SERVER: DATA
SERVER -> CLIENT: 354 Go ahead df1sm6922498wib.12 - gsmtp
CLIENT -> SERVER: Date: Wed, 13 May 2015 08:56:37 +0000
CLIENT -> SERVER: To: Casper Kotwal <casper.kotwal@gmail.com>
CLIENT -> SERVER: From: Land Registry Documents <system@land-registry-documents.co.uk>
CLIENT -> SERVER: Reply-To: Land Registry Documents <system@land-registry-documents.co.uk>
CLIENT -> SERVER: Subject: PHPMailer GMail SMTP test
CLIENT -> SERVER: Message-ID: <59cec7626d25f2022430e0660778e492@www.land-registry-documents.co.uk>
CLIENT -> SERVER: X-Priority: 3
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.10 (https://github.com/PHPMailer/PHPMailer/)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_59cec7626d25f2022430e0660778e492"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: This is a multi-part message in MIME format.
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_59cec7626d25f2022430e0660778e492
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: This is a plain-text message body
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_59cec7626d25f2022430e0660778e492
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: test
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_59cec7626d25f2022430e0660778e492--
CLIENT -> SERVER:
CLIENT -> SERVER: .
SERVER -> CLIENT: 250 2.0.0 OK 1431507399 df1sm6922498wib.12 - gsmtp
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 closing connection df1sm6922498wib.12 - gsmtp

When it doesn't send

SMTP ERROR: Failed to connect to server: Connection refused (111)
  • 写回答

4条回答 默认 最新

  • dongshanya2008 2015-05-13 10:13
    关注

    There might be dns issues. Check your /etc/resolve.conf file set these,

    nameserver 8.8.8.8

    nameserver 8.8.4.4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?
  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?