user

Jo Micheal

20 Jan 2022

stream_socket_client(): Unable to connect to tcp://smtp.gmail.com:587 (Network is unreachable)

Laravel

Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): Unable to connect to tcp://smtp.gmail.com:587 (Network is unreachable)

I am trying to use SMTP from Gmail with my laravel app but it didn't work when I switched to the live server I am getting this error 

What should I do? here is the .env config which I am uisng 

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME={my_email}@gmail.com
MAIL_PASSWORD="PASSWORD"
MAIL_FROM_NAME="Website"
MAIL_FROM_ADDRESS={my_email}@gmail.com
MAIL_ENCRYPTION=tls

I tried to change the port to 443 and also i changed tsl to ssl & nothing happen the same error 

Comments

Joseph Morgan

20 Jan 2022

Best Answer

best answer

This config working for me when I am using Server supports HTTPS & SSL when I used a server without SSL (HTTP) it doesn't work until I switched the smtp with "sendmail”

MAIL_MAILER=sendmail

so your configuration should looks like 

MAIL_MAILER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME={my_email}@gmail.com
MAIL_PASSWORD="PASSWORD"
MAIL_FROM_NAME="Website"
MAIL_FROM_ADDRESS={my_email}@gmail.com
MAIL_ENCRYPTION=tls

Good luck

Replies

Jo Micheal

20 Jan 2022

Wow, this works for me, never heard of sendmail thank you so much

© 2024 Copyrights reserved for web-brackets.com