简体   繁体   中英

Laravel 8: Connection could not be established with host smtp.gmail.com

I'm trying to send a simple email from my laravel 8 app using Google SMTP server, but it doesn't work, I'm getting this error:

Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): SSL:

or

stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed 

I found many SO post regarding this issue but none of them worked for me, here's a list of what I have tried:

  • Enabling less secure apps in the google account
  • using ports 465 and 587
  • Using smtp.googlemail.com and smtp.gmail.com
  • Using MAIL_ENCRYPTION=tls and ssl
  • Changing 'stmp' to 'sendmail'
  • Blocking switmailer's ssl constraint

Is there something else I can try?

Here's my mail configuration, although I've tried many versions of it:

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=address@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

我遇到了同样的问题,我只是禁用了我的防病毒软件(Avast/Windows 10)及其工作。

Try this and add the extra auth mode env variable

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=direction@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
MAIL_AUTH_MODE=login

Now go to config/mail.php

and change

    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'timeout' => null,
        'auth_mode' => null,
    ],

to

    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'timeout' => null,
        'auth_mode' => env('MAIL_AUTH_MODE'),
    ],

Finally, it was a problem with Windows. I found some posts pointing that windows just can't execute some mail services. I tried the exact same code in a computer with Ubuntu and it worked at first try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM