1. 程式人生 > >phpmailer發郵件提示SMTP->ERROR: Failed to connect to server的解決方法

phpmailer發郵件提示SMTP->ERROR: Failed to connect to server的解決方法

原文連結

使用phpmailer外掛發郵件失敗提示:SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: [email protected] Mailer Error: The following From address failed: [email protected]

連線伺服器失敗:連線超時(110)

在本地(windows)測試的時候一切正常,一發到伺服器(centos)上就提示以上錯誤了。本地正常說明使用者名稱,密碼都沒錯,設定也沒錯,是伺服器的設定問題。到網上找了好久,都沒找到可行的方法。

我是用gmail的服務,包括在iptables中新增465埠,關閉iptables,關閉selinux 都不行。測試了php函式fopen,fsockopen,pfscockopen都正常。期間還使用163郵箱測了下,同樣提示以上錯誤。

後面查啊查,查到了一個貼子,http://drupal.org/node/805834  看13樓,大意是說可能是系統開啟了ipv6,而php至少在v5.3.2版本前,在處理ipv6上有些已知的bug......如果是這種情況,可以把smtp的伺服器直接設定成ipv4地址.....

所以來排查下。(如果你趕時間的話,直接拖到下文解決方法設定上試下吧。)

1.看下是否開啟了ipv6

$ ifconfig eth0

eth0      Link encap:Ethernet  HWaddr 00:16:3B:E8:F5:26

         inet addr:216.24.198.11  Bcast:216.24.198.127  Mask:255.255.255.128

         inet6 addr: fe80::216:3eff:fee8:f226/64 Scope:Link

         inet6 addr: 2604:6600:5::5769:54ef/64 Scope:Global

看inet6 addr說明開啟了支援ipv6

2.連線下gmail的smtp看是否能連線上,gmail的smtp的埠是 465

2.1 telnet 下

$telnet smtp.gmail.com 465

提示找不到telnet命令。

2.2 檢視下是否安裝了telnet

$rpm -qa|grep telnet

2.3 什麼都沒提示,說明沒有安裝。telnet有服務端和客戶端,缺少哪個安裝哪個。直接yum。

#yum -y install telnet

安裝服務端

#yum -y install telnet-server

2.4 安裝成功後編輯/etc/xinetd.d/telnet

# vi /etc/xinetd.d/telnet

disable = yes

改成

disable = no

2.5 開啟xinetd

#service xinetd start

2.6 測試連線本地

$ telnet localhost

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

..

連線正常

2.7 連線gmail 的smtp 埠是 465

$ telnet smtp.gmail.com 465

Trying 2607:f8b0:400e:c00::6d...

有類似這麼一串2607:f8b0:400e:c00::6d 的話說明連的是ipv6,一直卡著連不上。

2.8 ping 下gmail的smtp,找到它的ipv4

$ ping smtp.gmail.com

PING gmail-smtp-msa.l.google.com (74.125.141.108) 56(84) bytes of data.

64 bytes from da-in-f108.1e100.net (74.125.141.108): icmp_seq=1 ttl=50 time=33.5 ms

74.125.141.108 就是它的ipv4地址

2.9 telnet 到ipv4上看下

$ telnet 74.125.141.108 465

Trying 74.125.141.108...

Connected to 74.125.141.108.

Escape character is '^]'.

出現以上這些表示可連線上。看來是預設連線到ipv6的地址上了。

3.解決方法

其中一個方法是禁用伺服器的ipv6。其實更好的方法是在傳送郵件的程式碼裡把smtp的地址設定為ipv4,如下:

1 $mail->Host       = "173.194.79.108";      // sets GMAIL as the SMTP server  smtp.gmail.com

然後我測試傳送了一下,成功!

所以,提示Failed to connect to server: Connection timed out (110)

The following From address failed郵件發不了的問題之一可能是因為ipv6連線不上導致的。也跟php沒什麼關係,不是php的bug,因為我們這連線測試用talnet連線的,一樣優先連線到的是ipv6,不是php中使用程式碼連的。

4.telnet 不太安全,所以測完把它給禁掉,以後有需要再開啟

#vi /etc/xinetd.d/telnet

disable = no

改成

disable = yes

停止服務

# service xinetd stop

5.附上gmail中使用phpmailer發郵件的配置

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <?php include("mailsender/class.phpmailer.php");

相關推薦

phpmailer郵件提示SMTP->ERROR: Failed to connect to server解決方法

原文連結 使用phpmailer外掛發郵件失敗提示:SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From addres

outlook等客戶端工具外郵件提示550 5.7.1 Unable to relay for

Unable to relay for問題現象:outlook、foxmail等客戶端工具外發郵件提示550 5.7.1 Unable to relay for(發內網郵件不會)、網頁方式發送外網和內網郵件都可以。解決辦法:可能性1:在exchange郵件服務器中,發現默認的SMTP虛擬服務沒有啟用;於是啟動

解決 SMTP Error: Could not connect to SMTP host. 問題

我在使用PHPmailer發郵件時候,遇到了這個問題“SMTP Error: Could not connect to SMTP host.”,分享一下解決方法。 這個錯誤是PHP版本7產生的。如果我將PHP更改為5,它就可以工作了。 1.首先檢視PHP環境擴充套件中是否開啟了socket 和openss

sendmail郵件提示Domain name required for sender address問題解決方案

今天有一封郵件突然發不出去了,提示錯誤資訊:553 5.5.4 <di>...Domain name required for sender address di 上網搜尋,答案都說是因為找不到伺服器,需要改伺服器名稱或域名檢查,但是我檢查了伺服器名稱,也檢查了

putty提示Network error:Software caused connection abort解決方法

最近使用putty的時候老是提示 network error software caused connection abort 網路錯誤軟體造成連線中斷 下面給出解決putty連線中斷辦法: 1.在linux伺服器端設定: vi /etc/ssh/sshd_config 找

Host is not allowed to connect to this MySQL server解決方法

his allow body ros root all post ges soft 在裝有MySQL的機器上登錄MySQL mysql -u root -p密碼 執行use mysql; 執行update user set host = ‘%‘ where user

[轉]Host is not allowed to connect to this MySQL server解決方法

今天在Linux上面裝完MySQL,卻發現在本地登入可以,但是遠端登入卻報錯Host is not allowed to connect to this MySQL server,找了半天試了網上的一些方法都沒有解決,最終在一篇文章裡找到了解決方法,特意記錄一下。 先說說這個錯誤,其實就是我們的MySQL不

phpmailer SMTP ERROR: Failed to connect to server: (0) 解決辦法

函式沒有被禁用,openssl 也是開啟的,SMTP伺服器和埠正確的,排除ipv6等問題直接填寫ipv4的地址還是不行的話,就在程式碼里加上下面的吧。 $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' =>

Python smtp郵件提示錯誤554, b'DT:SPM 163 smtp1

使用163郵箱的SMTP服務,傳送到QQ郵箱時出現錯誤: 注意,你是用的password應該是授權碼不是你的郵箱登陸密碼。 授權碼可以在你開通SMTP服務的時候得到。 554錯誤彙總: •554 DT:SPM 傳送的郵件內容包含了未被許可的資訊,或被系統識別為垃圾郵件。請檢查是否有

【jenkins git】Failed to connect to repository:Error performing command:git.exe ls-remote-h

strong src command for error file 管理 conf blank jenkins使用git源碼管理報錯:Failed to connect to repository:Error performing command:git.exe ls-re

LR報:Error 27796 Failed to connect to server

慢慢 action sim prot doc 錯誤 分析 failed 最小 原錯誤信息: Action.c(58): Error -27796: Failed to connect to server "10.1.44.68:7013": [10048] Addr

Action.c(28): Error -27796: Failed to connect to server "xxxx": [10060] Connection timed out 問題分析 分類

Error -27796: Failed to connect to server "125.93.51.230:8080": [10061] Connection refused.. 2013.05.31,這個27796一直是我心中的痛,試過網上所有的方法了,還是不行,我只能懷疑是不是

rancher報錯ERROR: http://192.168.200.8:8080/v1 is not accessible (Failed to connect to 192.168.200.8 p

報錯前 INFO: Running Agent Registration Process, CATTLE_URL=http://192.168.200.8:8080/v1 INFO: Attempting to connect to: http://192.168.200.8:8080/v1 E

Redis第一次啟動,SHUTDOWN時提示: (error) ERR Errors trying to SHUTDOWN. Check logs.

今天我也是第一次玩redis,從下載到安裝到HelloWorld一切順風順水,誰知在最後關閉redis時,出現了(error) ERR Errors trying to SHUTDOWN. Check logs.錯誤。下面貼出我的解決過程(可能有點繁瑣):

Tomcat啟動失敗 提示Server Tomcat v7.0 Server at localhost failed to start.六種解決方法

Tomcat啟動失敗,提示Server Tomcat v7.0 Server at localhost failed to start 在一次檢視自己以前寫過的專案中,執行tomcat失敗,出現如圖提示 然而自己之前的專案執行時候都很正常,沒有出現這樣的錯誤,再次執行時候就出現這樣的錯誤,百思不得其解,

【Python錯誤】windows下使用pip/easy_install提示Fatal error in launcher: Unable to create process using...

windows下的python安裝完成後,會在python的安裝目錄scripts下生成幾個exe檔案,其中包括easy_install和pip, 我們將上述路徑新增到系統的環境變數後,在正常情況 下是可以使用,easy_install等工具的,但是在64位的系統中會出現

PHPMailer 郵件時 Extension missing: openssl 的解決方案

用phpmailer傳送郵件時 用公司部署在騰訊上的企業郵箱傳送時,傳送失敗 , 因為使用了SSL驗證,出現了“Extension missing: openssl”的錯誤 解決方案: 在php.ini 裡 開啟 extension=php_openssl.d

linux -mongodb 啟動問題(Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : )

-bash-4.1# ./mongo MongoDB shell version v3.4.6 connecting to: mongodb://127.0.0.1:27017 2017-09-20T20:02:14.620+0800 W NETWORK

linux使用mail命令郵件—第三方smtp

yum install mail  由於Linux 5級以下的版本預設使用sendmail傳送mail,關閉sendmail之後將無法傳送mail,而Linux 6卻可以,他們主要區別是使用mailx的版本不一樣.Linux6使用mailx 版本mailx-1

MySQL之——提示"mysql deamon failed to start"錯誤的解決方法

網站突然連線不上資料庫,於是直接重啟了一下伺服器。進到cli模式下,執行 service myqsld start 發現還是提示"mysql deamon failed to start"錯誤資訊 # /etc/init.d/mysqld start MySQL Dae