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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘