broncho's avatar

stream_socket_enable_crypto(): SSL operation failed with code 1 Laravel 7

Hello. I had a problem with sending emails using Google SMTP. I researched how to solve this but I still get the error stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed.

My declaration in .env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=app_code_password
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="${APP_NAME}"

I fix the config/mail.php file

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

I also add this line also on config/mail.php

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

Still doesn't work. I used php artisan config:clear many times. I set up my google account already with less secure apps on, activate the 2 step/way verification, and I use the app_code instead of my password.

0 likes
10 replies
engrkashi's avatar

@jec360 Just go to the file vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php and comment out the code $options = []; and paste the code $options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);

Now it's going to work with you alright, because it worked for me too

5 likes
taffytech's avatar

@engrkashi editing files in the /vendor folder is never the right answer - an anyone who does this will 100% end up breaking their own application, and potentially their git repo

2 likes
kolyayurev's avatar

I have solved this problem. Just added stream section to smtp config

 '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,
            'stream' => [
                'ssl' => [
                    'allow_self_signed' => true,
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                ],
            ],
        ],
9 likes
baumgars's avatar

Not working here. Although i use Laravel 8 but should make any difference.

askfromali's avatar

I am facing same issue . i also add this code 'stream' => [ 'ssl' => [ 'allow_self_signed' => true, 'verify_peer' => false, 'verify_peer_name' => false, ], But its not work for me.

Please or to participate in this conversation.