Laravel - Connection could not be established with host smtp.gmail.com [ #0]

后端 未结 13 574
无人及你
无人及你 2020-12-29 04:32

I\'m trying to send an email from Gmail using Laravel from localhost. I\'m getting this error: Connection could not be established with host smtp.gmail.com [ #0]

I\'

相关标签:
13条回答
  • 2020-12-29 05:03

    here's what is working with me

    MAIL_MAILER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=587
    MAIL_USERNAME=<your email>
    MAIL_PASSWORD=<your app password>
    MAIL_ENCRYPTION=tls
    

    if you are two auth verification with your account , should be generate new app password and use into you env file. this is what working with me.

    0 讨论(0)
  • 2020-12-29 05:04

    In Laravel project directory, edit config/mail.php and add the following:

    'stream' => [
            'ssl' => [
                'allow_self_signed' => true,
                'verify_peer' => false,
                'verify_peer_name' => false,
            ],
        ]
    

    It worked for me.

    Fyi, my SMTP settings are:

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=465
    MAIL_USERNAME=[Full Gmail Address]
    MAIL_PASSWORD=[Google App Password obtained after two step verification on Google Account Page]
    MAIL_ENCRYPTION=ssl
    
    0 讨论(0)
  • 2020-12-29 05:05

    Have you tried changing the encryption to tls? I currently use a Gmail SMTP sever to send emails from my Laravel app. I use TLS and port 587

    0 讨论(0)
  • 2020-12-29 05:06

    Change mail driver in both .env and mail.php into MAIL_DRIVER=mailgun

    0 讨论(0)
  • 2020-12-29 05:11

    For me, it turned out TripMode blocked nginx & php-fpm. So make sure no app like this or firewall is blocking the connection to the mail server.

    0 讨论(0)
  • 2020-12-29 05:13

    You can't send emails from your localhost by default.

    If you configure your files correctly, you would be able to send emails from it.

    You could also try to upload the site on an server or production zone. There it will work.

    0 讨论(0)
提交回复
热议问题