Laravel SMTP send mail using gmail SMTP

Many Web server dose not enable Mail service by defaule. So, Today we are going to learn Laravel SMTP send mail using Gmail SMTP. Also, Let's see how we can send mail using Laravel Gmail SMTP. We can easily set up the SMTP driver for the Laravel application.

Laravel SMTP send mail using Gmail SMTP

Once we are ready with Laravel let's start the Laravel SMTP setting using Gmail SMTP step by step. Let's open the ".env" file then follow the instruction

  1. First, we need to change the MAIL_DRIVER to smtp
  2. We need to set up the MAIL_HOST like "" or ""
  3. We need to set up the MAIL_PORT correct port for TLS and SSL like 587, 445, 25 etc...
  4. provide the username for the authentication MAIL_USERNAME
  5. provide the password for the authentication MAIL_PASSWORD
  6. set up the encryption MAIL_ENCRYPTION for the authentication SMTP detail

After, setting up the server detail ".env" look like


Finally, We are ready with the SMTP If you are using Gmail as SMTP server then make sure don't forget to enable Less Secure app.

Now, let's check Laravel SMTP is working on not by sending the mail using Laravel like.

Route::get('/send-mail', function () {
    Mail::send('emails.laravelhive',array('name' => 'Laravel Hive'), function ($message) {
        $message->from('','Laravel Hive');
$message->to('','Laravel Hive');
$message->subject('Laravel SMTP send mail using gmail SMTP');
    print 'Mail sent';

Now, let's create the email template laravelhive.blade.php into the "resources/views/emails" directory.

        <h1>Welcome to {!! $name !!}!</h1>

Finally, We are ready for sending the testing email by following "http://localhost:8000/send-mail" URL.


Related Posts: