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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵