We noticed you're using an ad blocker

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Laravel 6 contact form tutorial

world cup 2023

WorldCup 2023

Get update standing, score, poll

Get Now

Contact form is most often an important part of any website. If you are a new Laravel developer then this post will help you to learn a step by step process for how to make a contact us form and submit for sending an e-mail to your desired email address. To send e-mail from a contact form we need to know about how to send e-mail in Laravel framework. In Laravel framework, e-mail sending is really simple. We can send e-mail in various way with same e-mail API that Laravel provides. Before we start, I'll recommend you to read a previous post on sending email laravel. Let's make a contact form in using Laravel so that user can send an email by our website contact form.


Table of Content

  • Make routes
  • Create a contact form
  • Make a controller for handle form request
  • Contact form validation
  • Mail configuration
  • Test the contact form


Make routes

Let's define 2 routes in web.php file in routes directory of Laravel project.



Create a contact form

Now make a contact.blade.php file in resources/views folder and do the contact form markup.

<form action="{{ ur1('contact-us')" method="post"› 

    <div class="form-group"›
       <input type="text" name="name" class="form-contror"> 
    <div class="form-group"›
       <input type="email " name="email " class="form-control">
    <div class="form-group"›
       <textarea name="message_body" class="form-control"></textarea>
    <button type="submit" class="btn btn-primary">Submit</button>



Make a controller for handle form request

Make a contact form handler controller via artisan command.

php artisan make:controller ContactUsController


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Mail;

class ContactUsController extends Controller
    public function index()
        return view('contact');

    public function handleForm(Request $request)

        $this->validate($request, ['name' => 'required', 'email' => 'required|email', 'message_body' => 'required|min:20']);

        $data = ['name' => $request->get('name') , 'email' => $request->get('email') , 'messageBody' => $request->get('message_body') ];

        Mail::send('email', $data, function ($message) use ($data)
            $message->from($data['email'], $data['name']);
            $message->to('info@laravelarticle.com', 'Admin')
                ->subject('Laravel Article Feedback');

        return redirect()
            ->with('success', 'Thank you for your feedback')




Mail Configuration

Set mail credentials on env

MAIL_USERNAME= email_address
MAIL_PASSWORD= email_pass

create an e-mail template for sending it on mail. Create a blade file name with email.blade.php in resources/views/emails

Message from : {{ $name }}
<p> Name: {{ $name }}</p>
<p>E-mail: {{ $email }}</p>
<p>Message: {{ $messageBody }}</p>


Test the contact form

Now browse http://example.com/contact-us and fill up the name, email, message and submit the form. If you set up everything correctly then you will get an e-mail into your mail address.



Thank you for reading this tutorial post with patience. I hope, this tutorial post will help you to make contact feedback form on your website. If this post is helpful to you then please share it with others.


Share on

Related Post - Latest Post

Laravel Barcode generation tutorial

What's new in Laravel 9

Make laravel site super fast by page-cache!

Laravel maintenance mode bypass by Secret Route!

Laravel database backup automatically - cPanel shared hosting, VPS

Laravel Datatables - Ajax, Column, Buttons, Customization