Why am I unable to send mail using laravel 8 gmail smtp?

Viewed 1034

I'm trying to send a mail from my localhost laravel 8 app using Gmail SMTP after entering the configurations but keep getting

Swift_TransportException
Connection could not be established with host smtp.gmail.com :stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

I have turned on the Less Secure App settings on my gmail and even downloaded cacert.pem and added the location to my php.ini but it just keeps loading after submitting the form and then giving me the above error. What do I need to do to get it to work?

Here are my related .env file settings

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mygmailaddress
MAIL_PASSWORD=******
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=mygmailaddress
MAIL_FROM_NAME="${APP_NAME}"

mail.php

'default' => env('MAIL_MAILER', 'smtp'),

    'mailers' => [
        '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,
        ],

        'ses' => [
            'transport' => 'ses',
        ],

        'mailgun' => [
            'transport' => 'mailgun',
        ],

        'postmark' => [
            'transport' => 'postmark',
        ],

        'sendmail' => [
            'transport' => 'sendmail',
            'path' => '/usr/sbin/sendmail -bs',
        ],

        'log' => [
            'transport' => 'log',
            'channel' => env('MAIL_LOG_CHANNEL'),
        ],

        'array' => [
            'transport' => 'array',
        ],
    ],

    
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],


    'markdown' => [
        'theme' => 'default',

        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],

];

php.ini

openssl.cafile=C:\wamp64\ssl\cacert.pem
openssl.capath=C:\wamp64\ssl

Maybe I'm supposed to change something in my mail.php file? Or just one of the fields in the php.ini should be present? I've tried to change the smtp mail host, port and encryption to smtp.gmail.com, 465, and ssl in mail.php respectively, but that didn't work either. Neither did changing .env port to 587 and encryption TLS. What am I missing? Please help.

Fairly new to Laravel though, please be nice lol.

1 Answers

Can you try to change MAIL_PORT=587 . After than you need to give permission in your account to Less secure apps.

Related