3

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}"
Gamopo
  • 1,600
  • 1
  • 14
  • 22
  • check this [https://stackoverflow.com/questions/30556773/how-to-fix-stream-socket-enable-crypto-ssl-operation-failed-with-code-1](https://stackoverflow.com/questions/30556773/how-to-fix-stream-socket-enable-crypto-ssl-operation-failed-with-code-1) – Zakaria Ab Sep 17 '20 at 14:46
  • Can you send the mail config please. (Just omit the passwords etc) – Chris Townsend Sep 17 '20 at 15:23
  • @ChrisTownsend sure, I added it to the question – Gamopo Sep 18 '20 at 07:41

3 Answers3

5

I had the same problem, I just disabled my antivirus (Avast / windows 10) and its work.

anasmorahhib
  • 807
  • 9
  • 14
1

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'),
    ],

Chris Townsend
  • 2,586
  • 2
  • 21
  • 41
0

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.

Gamopo
  • 1,600
  • 1
  • 14
  • 22