Mail Send in Laravel Example Tutorial

Mail Send in Laravel Example Tutorial


Mail Send in Laravel 8 Example Tutorial 

Sending email in Laravel or any other project is very required. So, here we implement how to send emails in the Laravel app example easy way step by step. Many times we need to send emails to users which we want to invite or direct send emails using the form. 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 the Mail function to sending emails to users. So, Let’s start with an Email send in Laravel example tutorial with validations messages.

step 1: Install Laravel Project

First Install a Laravel project to run the below command

composer create-project --prefer-dist laravel/laravel Laravel_SendMail

Step 2: Setup Database Credentials

Create a new database custom auth and now open your .env file and add your database credentials

Step 3: Update SMTP Details in .env File

First update your email trap details in your .env file just like below, You can send an email via log. If you have not to email trap details got to this link and create a new account.

MAIL_USERNAME=your email
MAIL_PASSWORD='your password'

Step 4: 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.


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

Step 5: Update Controller

You can create a new controller or update these methods in your existing controller. Here we create a new controller you can also create a new after running the below command.

php artisan make:controller EmailController

After successfully create a new controller you can update the below code in your file.



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',
          'name' => 'required',
          'content' => 'required',

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

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

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

Step 6: Create a Blade FIle

Now you need to create a blade file where you show the email send the form in Laravel.


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Mail Send in Laravel Example</title>
<link rel="stylesheet" href="|Courgette|Pacifico:400,700">
<link rel="stylesheet" href="">
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<script src=""></script>
body {
    color: #000;
    background-image: url("background.jpg");
    font-family: "Roboto", sans-serif;
.contact-form {
    padding: 50px;
    margin: 30px auto;
.contact-form h1 {
    font-size: 42px;
    font-family: 'Pacifico', sans-serif;
    margin: 0 0 50px;
    text-align: center;
.contact-form .form-group {
    margin-bottom: 20px;
.contact-form .form-control, .contact-form .btn {
    min-height: 40px;
    border-radius: 2px;
.contact-form .form-control {
    border-color: #e2c705;
.contact-form .form-control:focus {
    border-color: #d8b012;
    box-shadow: 0 0 8px #dcae10;
.contact-form .btn-primary, .contact-form .btn-primary:active {
    min-width: 250px;
    color: #fcda2e;
    background: #000 !important;
    margin-top: 20px;
    border: none;
.contact-form .btn-primary:hover {
    color: #fff; 
.contact-form .btn-primary i {
    margin-right: 5px;
.contact-form label {
    opacity: 0.9;
.contact-form textarea {
    resize: vertical;
.bs-example {
    margin: 20px;
<div class="container-lg">
	<div class="row">
		<div class="col-md-8 mx-auto">
			<div class="contact-form">
				<h1>Get in Touch</h1>
                    <div class="alert alert-success">
                        {{ session()->get('message') }}
                <form action="{{ route('') }}" method="post">
					<div class="row">
						<div class="col-sm-6">
							<div class="form-group">
								<label for="inputName">Name</label>
								<input type="text" name="name" class="form-control" placeholder="Enter Name">
                                <span class="text-danger"> {{ $message }} </span>
						<div class="col-sm-6">
							<div class="form-group">
								<label for="inputEmail">Email</label>
								<input type="email" name="email" class="form-control" placeholder="Enter Email">
                                <span class="text-danger"> {{ $message }} </span>
					<div class="form-group">
						<label for="inputSubject">Subject</label>
                        <input type="text" name="subject" class="form-control" placeholder="Enter subject">
                        <span class="text-danger"> {{ $message }} </span>
					<div class="form-group">
						<label for="inputMessage">Message</label>
                        <textarea name="content" rows="5" class="form-control" placeholder="Enter Your Message"></textarea>
                        <span class="text-danger"> {{ $message }} </span>
					<div class="text-center">
						<button type="submit" class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button>

Step 6: Email Template

When we send an email then we need a template that shows the message.


<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 it works for you. If you have any questions don’t hesitate to drop a message below.


Post a Comment