Phpmailer: SMTP ERROR: Failed to connect to server: Network is unreachable (101)

Created on 17 Jun 2017  Â·  25Comments  Â·  Source: PHPMailer/PHPMailer

I have setup gmail SMTP for wordpress but while sending test mail it is showing the error

Connection: opening to ssl://smtp.gmail.com:80, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:80 (Network is unreachable)
SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Server Info
OS: Linux server2.hostsoch.in 2.6.32-673.26.1.lve1.4.23.el6.x86_64 #1 SMP Thu Mar 9 15:13:22 EST 2017 x86_64
PHP version: 5.6.30
WordPress version: 4.8
WordPress multisite: No
openssl: Available
allow_url_fopen: Disabled
stream_socket_client: Available
fsockopen: Available
cURL: Available
cURL Version: 7.53.1, OpenSSL/1.0.1e

Most helpful comment

Presumably because the network the other server is on doesn’t permit access to it. It’s very common for ISPs to block outbound SMTP. The tests in the troubleshooting guide will help you find out.

All 25 comments

Why are you trying to send on port 80? That's not going to work; use port 465 or use TLS on port 587.

I have tried it again with port 465 with SSL, still its giving the same error
Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:80 (Network is unreachable)
SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Well, I can only conclude that the networking on your server is limited in some way - most likely that your ISP blocks outbound SMTP. Read the troubleshooting guide for some tests that will enable you to find out exactly what they are doing.

Also, you should never need to disable certificate verification when connecting to Google.

2018-06-15 12:02:39 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
2018-06-15 12:07:00 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable) [/var/www/html/mail/class.smtp.php line 298]
2018-06-15 12:07:00 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

what to do?

It really helps if you read the error message. This might come as a surprise, but when it says "Network is unreachable" it means it can't reach your network. If you fix your network (probably removing whatever block your ISP puts on outbound SMTP), your script will be able to work; it's not the script that's causing the problem.

How m i able to know... Which thing is blocking SMTP

On Fri, 15 Jun 2018, 19:24 Marcus Bointon, notifications@github.com wrote:

It really helps if you read the error message. This might come as a
surprise, but when it says "Network is unreachable" it means it can't reach
your network. If you fix your network (probably removing whatever block
your ISP puts on outbound SMTP), your script will be able to work; it's not
the script that's causing the problem.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPMailer/PHPMailer/issues/1077#issuecomment-397628410,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AedFbNLdtwC1uWKmO3VlpWra1sp5lnFsks5t87yggaJpZM4N9SNG
.

You could try the techniques listed in the troubleshooting guide, or ask your ISP.

2018-06-15 15:06:56 Connection: opening to smtp.gmail.com:587, timeout=300,
options=array ()
2018-06-15 15:06:56 Connection: opened
2018-06-15 15:06:57 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP
q10-v6sm13630180pfj.7 - gsmtp
2018-06-15 15:06:57 CLIENT -> SERVER: EHLO localhost
2018-06-15 15:06:57 SERVER -> CLIENT: 250-smtp.gmail.com at your service,
[2409:4055:711:5ea8:a9e4:eea:2f79:4757]250-SIZE
35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8
2018-06-15 15:06:57 CLIENT -> SERVER: STARTTLS
2018-06-15 15:06:58 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-06-15 15:06:58 CLIENT -> SERVER: EHLO localhost
2018-06-15 15:06:58 SERVER -> CLIENT: 250-smtp.gmail.com at your service,
[2409:4055:711:5ea8:a9e4:eea:2f79:4757]250-SIZE
35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN
OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250
SMTPUTF8
2018-06-15 15:06:58 CLIENT -> SERVER: AUTH LOGIN
2018-06-15 15:06:59 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2018-06-15 15:06:59 CLIENT -> SERVER: xxx
2018-06-15 15:06:59 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2018-06-15 15:06:59 CLIENT -> SERVER: xxx
2018-06-15 15:07:00 SERVER -> CLIENT: 534-5.7.14 <
https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu7534-5.7.14
I4GdCsbGomXBLQECFsHPW8n5eh58PJtsUib_xeblXR_BSFFcTV6hIpcSEBA7QC7ua6OmyO534-5.7.14
Roj-yoIoywWsBUYE0o9lZOHyRfWo4CxqG6VEWmmduzORv16D8iZaKOxmYw3l1BjcjdgbGX534-5.7.14
HGLgs4lLPdzGzAP5_Sq1HjbBLYXM7u-PVH6ImXPXAPsL4JuU9VCYixtFzKDgnLwMNb3EDo534-5.7.14
zNpEwyEjpIiCFhlCgL7NnSXxj-tq4> Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 q10-v6sm13630180pfj.7 - gsmtp
2018-06-15 15:07:00 SMTP ERROR: Password command failed: 534-5.7.14 <
https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu7534-5.7.14
I4GdCsbGomXBLQECFsHPW8n5eh58PJtsUib_xeblXR_BSFFcTV6hIpcSEBA7QC7ua6OmyO534-5.7.14
Roj-yoIoywWsBUYE0o9lZOHyRfWo4CxqG6VEWmmduzORv16D8iZaKOxmYw3l1BjcjdgbGX534-5.7.14
HGLgs4lLPdzGzAP5_Sq1HjbBLYXM7u-PVH6ImXPXAPsL4JuU9VCYixtFzKDgnLwMNb3EDo534-5.7.14
zNpEwyEjpIiCFhlCgL7NnSXxj-tq4> Please log in via your web browser
and534-5.7.14 then try again.534-5.7.14 Learn more at534 5.7.14
https://support.google.com/mail/answer/78754 q10-v6sm13630180pfj.7 - gsmtp
SMTP Error: Could not authenticate.
2018-06-15 15:07:00 CLIENT -> SERVER: QUIT
2018-06-15 15:07:00 SERVER -> CLIENT: 221 2.0.0 closing connection
q10-v6sm13630180pfj.7 - gsmtp
2018-06-15 15:07:00 Connection: closed
SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed.
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Because you ignored the advice to use the latest version, you exposed your encoded password to everyone (I edited it out of your post), so I suggest you change it. This is just one reason you should not hijack other people's threads.

Do you think that these links could have something to do with it?

Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 q10-v6sm13630180pfj.7 - gsmtp
2018-06-15 15:07:00 SMTP ERROR: Password command failed:
534-5.7.14 <
https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbu7

It didn't occur to you that those might tell you something? Or that looking in the guide to see if those are mentioned in there might be appropriate?

@Synchro I am facing the same error I tried like you say.
I have 2 servers on one it's working but on the second where I needed it's not working.
Invalid address: (setFrom) 2019-07-05 13:23:06 Connection: opening to send.one.com:587, timeout=300, options=array () 2019-07-05 13:23:08 Connection failed. Error #2: stream_socket_client(): unable to connect to send.one.com:587 (Network is unreachable) [/home/elitepropertydes/public_html/Cookies/html/pages/phpmailer/class.smtp.php line 298] 2019-07-05 13:23:08 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Your server or network has a problem, not your script.

But why is it working on another server?

Presumably because the network the other server is on doesn’t permit access to it. It’s very common for ISPs to block outbound SMTP. The tests in the troubleshooting guide will help you find out.

Oh, I understand thank you for this.

Hi,

stream_socket_client(): unable to connect to tcp://localhost:587 (Connection refused)

Using CyberPanel. CSF flushed but no luck.

Please help.

Please don't post comments on long-closed tickets.

You have two problems here:

  • Your local mail server (if you have one) does not appear to be listening on port 587.
  • Attempting to use port 587 on localhost is very likely to fail anyway, because 587 expects you to use STARTTLS encryption, and you can't get a valid certificate for localhost. There's no point in using encryption to localhost, so disable it and use port 25.

Good day to you,

i am having the same problem of

2020-02-09 12:16:33 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2020-02-09 12:16:34 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:587 (Network is unreachable) [/home/heatuiye/public_html/vendor/phpmailer/phpmailer/src/SMTP.php line 349]
2020-02-09 12:16:34 SMTP ERROR: Failed to connect to server: Network is unreachable (101)

should i follow the troubleshooting guide on git or i contact my server customer care ?

should i follow the troubleshooting guide on git or i contact my server customer care ?

Yes. It looks like your ISP blocks outbound SMTP, so ask them.

I Contacted my Hosting and the socket was opened

and also if yout using gmail XOAUTH2 this see very helpful

https://github.com/PHPMailer/PHPMailer/wiki/Using-Gmail-with-XOAUTH2

Cool. That guide in the wiki needs updating for PHPMailer 6, and it's open for edits, so please feel free to make any changes if it looked or worked differently to what you found.

First, I understand the problem, and solution related to this issue, but:

CTRL + F with SMTP ERROR: Failed to connect to server: Network is unreachable (101) on https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
doesn't bring any luck, but google brought me to this issue.

Maybe we can add one section on the Troubleshooting page so typing Network is unreachable (101) in search would bring some explanations.

Cheers

@nicovv44 Done.

Hello sir.
I have a problem the same.pls could you check

2020-04-08 10:31:24 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Network is unreachable) [/home/mehllannar/css.mehllannar.me/vendor/phpmailer/phpmailer/src/SMTP.php line 349]
2020-04-08 10:31:24 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
2020-04-08 10:31:23 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array()

@Mehllan your hosting provider is blocking outbound SMTP, as explained in the troubleshooting guide.

Hello ,

Be sure to change the account password after you hosting provider opens the
connection, after that your good to go

BR.

On Wed, Apr 8, 2020 at 11:42 AM Marcus Bointon notifications@github.com
wrote:

@Mehllan https://github.com/Mehllan your hosting provider is blocking
outbound SMTP, as explained in the troubleshooting guide.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/PHPMailer/PHPMailer/issues/1077#issuecomment-610885493,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AJSCQPLA6VSBKGPVZPVQ45TRLRIK7ANCNFSM4DPVENDA
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nsssim picture nsssim  Â·  6Comments

wilon picture wilon  Â·  4Comments

Synchro picture Synchro  Â·  5Comments

aduh95 picture aduh95  Â·  4Comments

AndroidDesigner picture AndroidDesigner  Â·  4Comments