How to send mail example in Laravel 6

  • 30-03-2022
  • 1133
  • Laravel 6
  • Haresh Chauhan

Laravel Provides mail sending system, So I will tell you in this how-to setup with mail. I will give you instructions step by step mail sending example. In this post, we can easily send emails without too many hassles with your requirements. Laravel provides easy send link mail template, Attachment, CC, BCC, and many more options. we can use the function without any exception. We will discuss in this post. In Laravel email, You can use the Blade syntax and inject data into your templates. In Laravel email, you can also use the core PHP method for send mail and you can also use some email service providers such as MailGun, MailChimp, Sendmail, SMTP, mandrill, mail, Gmail, etc. Laravel provides several ways to send mail. So, now performing this task.


Mail::send([‘text’=>’text.view’], $data, $callback);

Step 1 : Setup .env

In this step we require to change in .env file. So,let's change on that file.



Step 2 : Add Routes

Here,we need to make controller following below command.

php artisan make:controller MailController


    | Web Routes
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!

Step 3 : Put code into MailController

In this step we need to copy MailController file code and put into your project file.


    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use Mail;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    class MailController extends Controller {
       public function basic_email() {
          $data = array('name'=>"Dharmesh Chauhan");
          Mail::send(['text'=>'mail'], $data, function($message) {
             $message->to('', 'webappfix')->subject('Laravel Basic Testing Mail');
             $message->from('','Dharmesh Chauhan');
          echo "Basic Email Sent. Check your inbox.";
       public function html_email() {
          $data = array('name'=>"Dharmesh Chauhan");
          Mail::send('mail', $data, function($message) {
             $message->to('', 'webappfix')->subject('Laravel HTML Testing Mail');
             $message->from('','Dharmesh Chauhan');
          echo "HTML Email Sent. Check your inbox.";
       public function attachment_email() {
          $data = array('name'=>"Dharmesh Chauhan");
          Mail::send('mail', $data, function($message) {
             $message->to('', 'webappfix')->subject('Laravel Testing Mail with Attachment');
             $message->from('','Dharmesh Chauhan');
          echo "Email Sent with attachment. Check your inbox.";

Step 4 : Create Blade file

In the last step we require to create blade file. Copy this file and put code on your file and save it.


<!DOCTYPE html>
    <html lang="en">
            <title>Mail Template -</title>
            <h1>Hi, {{ $name }}</h1>
            <p>Sending Mail from Laravel.</p>

Now, We are ready to run example ,So let's run using quick command.

php artisan serve

Open your browser and fire this url one by one and check your mail inbox.

Run the following URL to test basic email.


Run the following URL to test the HTML email.


Run the following URL to test the HTML email with attachment.


If you want to use gmail account into .env file then you must need to set two configuration into gmail account.

Configuration 1

Open you gmail account and following this direction Account > Security > Less secure app access If Less secure app access is OFF Switch to ON.

Configuration 2

Follow this link and click the Continue button.

I hope it can helpful for you.


We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :