Send Email in Laravel Example Tutorial Step by Step Guide

Sending email in laravel or any other project is very required. So, here we implement how to send email in laravel app example easy way step by step.

Many times we need to send mail to user which we want invite or direct send email using the form. This example show you Send Email in Laravel Tutorial Step by Step Guide easy way.

Laravel provides a clean, simple API over the popular SwiftMailer library with drivers for SMTP, Mailgun, Postmark, Amazon SES, and sendmail, allowing you to quickly get started sending mail through a local or cloud based service of your choice. Here we use Mail function to sending email to users.

Step 1: Update SMTP Details in .env File

First you need to update the mailtrap details in your .env file just like below, You can send email via log also. If don’t have mailtrap details visit this link and create a new mailtrap account.


Step 2: Add Routes

Now create two routes in your web.php file one for showing form and another is sending email to the user which you want. So, open the routes/web.php file and update the below routes on it;

Route::get('/email', 'EmailController@create');
Route::post('/email', 'EmailController@sendEmail')->name('');

Step 3: Update Controller

You can create new controller or update these methods in your existing controller. So, create a new controller using the following command:

php artisan make:controller EmailController

After successfully create new controller, open the app\Http\Controllers\EmailController.php file and update below code on it.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Mail;

class EmailController extends Controller
    public function create()

        return view('email');

    public function sendEmail(Request $request)
          'email' => 'required|email',
          'subject' => 'required',
          'content' => 'required',

        $data = [
          'subject' => $request->subject,
          'email' => $request->email,
          'content' => $request->content

        Mail::send('email-template', $data, function($message) use ($data) {

        return back()->with(['message' => 'Email successfully sent!']);

Step 4: Create Blade FIle

Now you need to create a blade file where you show email send form in laravel, So, navigate the resources/views directory and crate email.blade.php file. After that open resources\views\email.blade.php file and update the below code.

<!DOCTYPE html>
    <title>Mail Send in Laravel Example with</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//" rel="stylesheet">
    <meta name="csrf-token" content="{{ csrf_token() }}" />

    <div class="container">
        <h1>Mail Send in Laravel Example with <a href="">Coding Driver</a></h1>
              <div class="alert alert-success">
                  {{ session()->get('message') }}
        <form action="{{ route('') }}" method="post">
            <div class="form-group">
                <input type="email" name="email" class="form-control" placeholder="Enter Email">
                  <span class="text-danger"> {{ $message }} </span>

            <div class="form-group">
                <input type="text" name="subject" class="form-control" placeholder="Enter subject">
                  <span class="text-danger"> {{ $message }} </span>

            <div class="form-group">
                <textarea name="content" rows="5" class="form-control" placeholder="Enter Your Message"></textarea>
                  <span class="text-danger"> {{ $message }} </span>
            <div class="form-group">
                <button type="submit" class="btn btn-success save-data">Send</button>

Step 5: Email Template

When we send a email then we need to a template which is show the message. So, you need to create an another file named as email-template.blade.php file. After that open the resources\views\email-template.blade.php file and put the below code on it;

<div class="container">
     <div class="row justify-content-center">
         <div class="col-md-8">
             <div class="card">
                 <div class="card-header">Welcome!</div>
                   <div class="card-body">
                    @if (session('resent'))
                         <div class="alert alert-success" role="alert">
                            {{ __('A fresh mail has been sent to your email address.') }}
                    {!! $content !!}

Great! You successfully lean Email Send Example in Laravel. I hope its works for you. If you have any question don’t hesitate to dropping a message below.

6 thoughts on “Send Email in Laravel Example Tutorial Step by Step Guide”

  1. Pingback: Correo en Laravel – DAM
  2. Hi,
    thanks for your code.

    I have tried it, but it doesn’t work.
    This is my web.php:

    and I have created the EmailController with the sentence:
    php artisan make:controller EmailController

    I receive the error when I access to the route /email:
    Target class [EmailController] does not exist.

    Do you you have all the code in github?
    Can you help me?


    • Please create EmailController, if you are using another controller then update the controller in web.php file.


Leave a Comment