user image

Jo Micheal
Published in : 2022-01-20

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

Laravel

Swift_TransportExceptionConnection 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=smtpMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_USERNAME={my_email}@gmail.comMAIL_PASSWORD="PASSWORD"MAIL_FROM_NAME="Website"MAIL_FROM_ADDRESS={my_email}@gmail.comMAIL_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 Date : 2022-01-20

Best answers

11

Best answers

11

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=sendmailMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_USERNAME={my_email}@gmail.comMAIL_PASSWORD="PASSWORD"MAIL_FROM_NAME="Website"MAIL_FROM_ADDRESS={my_email}@gmail.comMAIL_ENCRYPTION=tls

Good luck

Jo Micheal Date : 2022-01-20

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

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

Increase Sanctum token length in Laravel x9
Publish date: 2022-07-16 | Comments: 2
How to check Laravel version?
Publish date: 2022-04-07 | Comments: 2
API CORS error in Laravel 9x
Publish date: 2022-08-03 | Comments: 2