Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel-Pablo's avatar

send emails with laravel and google gmail smtp SSL

After spending a day trying to make google Gmail send and email finally I achieved it and I want to share the way and codes I use to make it happen... maybe you are trying to make the same

On the .env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=this code is generated read more down
MAIL_ENCRYPTION=ssl
[email protected]
MAIL_FROM_NAME=yourName
MAIL_LOG_CHANNEL=NULL

On the mail.php

return [
    'driver' => env('MAIL_DRIVER'),
    'host' => env('MAIL_HOST'),
    'port' => env('MAIL_PORT'),
    'from' => [
        'address' => env('MAIL_FROM_ADDRESS'),
        'name' => env('MAIL_FROM_NAME'),
    ],
    'encryption' => env('MAIL_ENCRYPTION'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
    'log_channel' => env('MAIL_LOG_CHANNEL'),
];

I add this code on the file that calls the /Mail::To() ON THE TOP I don't know if that is useful but I just added and all is working so I will not remove it... Just in case it's needed

use Illuminate\Support\Facades\Mail;

Okay that's it for the code now you must

  1. Enter your Google account
  2. go to account -> security
  3. then fill up the two-ways authentication to google
  4. After doing all that you must GENERATE AN APP CODE
  • on the same security tap, you will find something called APP Password enter and generate one.
  1. with that code COPY and PASTE IT on the .env file
MAIL_PASSWORD= HERE!!

that code allows you to send emails with google GMAIL

hope someone reaches this post and be useful for the Laravel community and Laracast too

Santino codex / If this helps you leave me a comment :)

0 likes
4 replies
Snapey's avatar

@shadrix blatant plug for article that is not even relevant to the question, and posted 8 months late.

This should be marked as SPAM .. Will you remove it?

1 like

Please or to participate in this conversation.