-1

I want to use Gmail to send emails through Laravel. When I apply through localhost, the email is sent correctly. But it gives the following error on the server and the email is not sent.

local.ERROR: Swift_TransportException: Connection could not be established with host smtp.gmail.com $:stream_socket_client(): unable to connect to tcp://smtp.gmail.com:587 (Connection timed out)

2 Answers2

0

Hello I had the same problem probably your solution is like that, because this helps me to resolved my issue

Create a custom app in you Gmail security settings.

  1. Log-in into Gmail with your account
  2. Navigate to https://security.google.com/settings/security/apppasswords
  3. In 'select app' choose 'custom', give it an arbitrary name and press generate
  4. It will give you 16 chars token.` Use the token as password in combination with your full Gmail account and two factor authentication will not be required.

Note: The link in step 2 will work only if you have 2-factor-authentication enabled.

For Refference: link

sta
  • 8,667
  • 4
  • 29
  • 47
0

use mail trap for testing

link https://mailtrap.io/ where you get your all smtp credential and put in .env file

  • thanks. It was a really good website. My application is working properly and the email was received in mailtrap. There is definitely a problem connecting to Gmail while the Gmail security settings are in place. But the question is, where is the problem? – sohrab azinfar Feb 05 '21 at 15:37
  • Could it be a problem with my server server? I bought the server from Hetzner Online AG in Germany. Could the IP range of this server be limited by Google? – sohrab azinfar Feb 05 '21 at 15:47
  • might be your credentials issue, check your credentials – Chaudhry Asif Feb 05 '21 at 15:51
  • Authentication information is correct. The server's suffering is probably blacklisted. – sohrab azinfar Feb 05 '21 at 16:36