Create Validate Laravel 8 Contact Form with Send Email

In this tutorial you will learn about the Create Validate Laravel 8 Contact Form with Send Email and its application with practical example.

In this Create Validate Laravel 8 Contact Form with Send Email tutorial I will show you how to Create a contact form with validation in laravel. We will also send an email to admin on form submission and save contact form input in the database.

In this tutorial, you will learn to create a contact form UI using Bootstrap CSS in laravel. I will also  show you how to validate contact form, sending email to the admin with contact form values using mailtrap.

Create & Validate Laravel 8 Contact Form with Send Email

In this step by step tutorial I will demonstrate you how to create a contact form in laravel with validation and sending email on form submission.

  1. Install Laravel Project
  2. Setup Database
  3. Create Migration
  4. Add Route
  5. Add Controller
  6. Add Blade.

Step 1: Install Laravel Project

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command


Step 2: Setup Database

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3: Create Migration

Now, in this step we will create model and migration file. Please run the following command:

After this command you will find one file in following path “database/migrations” and you have to put bellow code in your migration file for create students table

Now, in this step we will create model and migration file. Please run the following command:

Now, we will put following code in Contact model :

App/Models/Contact.php

Step 4: Add Route

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 5: Add Controller

Now, lets create a controller named ContactController using command given below –

Now, we will add following two methods in ContactController

1)contactForm()

2)storeContactForm()

app/Http/Controllers/ContactController.php

Step 6: Add Blade

Now, we will create two blade file contactForm and second is mail file.

1) contactForm.blade.php

2) contactMail.blade.php

So let’s just create following file and put bellow code.

resources/views/contactForm.blade.php

resources/views/contactMail.blade.php

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Create Validate Laravel 8 Contact Form with Send Email and its application with practical example. I hope you will like this tutorial.