Hamsa K
4 min read | 5 years ago

Sending Mail via Gmail Smtp Server in Laravel

Sending Mail via Gmail Smtp Server in Laravel

Sending Mail via Gmail Smtp Server in Laravel

Setup Of Gmail SMTP Server In Laravel

Laravel use config/mail.php file for storing details related to sending emails. This file contains settings like MAIL_DRIVER, MAIL_HOST, MAIL_PORT, etc. For sending email we need to provide this information.
To add these setting, we don’t need to edit config/mail.php. We should store these details in the .env file.
Open your .env file which is located in your root directory and you will find below code related to email settings.


Now edit the details above as follows.


Don't forget to run php artisan config:cache after you make changes in your .env file.

Configure your Google Account
First of all, login to your gmail account. Under My account > Sign In And Security > Sign In to Google, enable two-step verification, and then generate app password,
Send Emails from your Laravel Application
At this point, all the basic setup has been completed. We can now write some Laravel PHP codes to send an email.
To get started, create any controller of choice where the mail sending logic will be handled, then in this controller write your codes using the code snippet below as a guide.

$data = array('name'=>"sender_name", "body" => "A test mail");
Mail::send('emails.mail', $data, function($message){
->subject('Laravel Test Mail');
$message->from('sender_mail_address','Test Mail');

In the above code, we are using our mail template as ’emails.mail’ file . hence we need to create an ‘emails’ folder and the mail.blade.php file at


Our test mail template mail.blade.php should just contains a few test codes as shown below.

Hello <strong>{{ $name }}</strong>,

simply create any route of your choice to and start sending mails from your Laravel application.

Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy