Simple Laravel Contact Us Form With Email Example

Today, We want to share with you Simple Laravel Contact Us Form With Email Example.In this post we will show you Create a Laravel Contact Us form with Email, hear for Laravel 5.7 Contact Form With File Attachment Script we will give you demo and example for implement.In this post, we will learn about Laravel 5.7 – Create Bootstrap Contact US Form using Form Request with an example.

Simple Laravel Contact Us Form With Email Example

There are the Following The simple About Simple Laravel Contact Us Form With Email Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Sending Email Messages in Laravel 5.7, so the Submit Contact Form in PHP Laravel 5.7 with toastr notifications jquery for this example is following below.

Setp 1 : Setup laravelcollective

Install Laravel Collective HTML Package with Install Laravel Application

cd myproject
cd myprojectname/public_html
composer require laravelcollective/html

config/app.php

// Laravel Add a Providers with aliases
'providers' => [
....
'Collective\Html\HtmlServiceProvider',
],
'aliases' => [
....
'Form' => 'Collective\Html\FormFacade',
],

Setp 2 : Database Configuration

the .env file >> Add the Laravel file settings credentials

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=example.db.name                                                                                               DB_USERNAME=example.db.username                                                                                           
DB_PASSWORD= example.db.password

Make Laravel Migrations for Feedback Us Table

php artisan make:migration create_feedback_us_table

database/migration/date_ create_feedback_us_table.php

increments('id'); $table->string('name'); $table->string('email'); $table->text('comment'); $table->timestamps(); });
    }

    public function down()
    {
       Schema::drop("feedbackus");
    }
}

Laravel run the following command

php artisan migrate

Setp 3 : Laravel Make The Model

Create a Laravel Model

php artisan make:model Feedback

app/Feedback.php

<?php

namespace App;
use Illuminate\Database\Eloquent\Model;
class Feedback extends Model
{

public $table = 'feedbackus';
public $fillable = ['name','email','comment'];

}

Setp 4 : Define Laravel the Route

routes/web.php

Route::get('feedback-us', 'FeedbackController@Feedback');
Route::post('feedback-us', ['as'=>'feedbackus.store','uses'=>'FeedbackController@FeedbackPost']);

Setp 5 : Make a Laravel Controller

app/Http/Controllers/FeedbackController.php

validate($request, [
        'name' => 'required',
        'email' => 'required|email',
        'comment' => 'required'
        ]);

       Feedback::create($request->all());

       return back()->with('success', 'Thanks for feedbacking us!');
   }
}

Setp 6 : Make Laravel the View

resources/views/Feedback.blade.php




Laravel 5.7 Feedback Form Example




Feedback Form

Laravel Contact Form With File Attachment Script

@if(Session::has('success'))
{{ Session::get('success') }}
@endif {!! Form::open(['route'=>'feedbackus.store']) !!}
has('name') ? 'has-error' : '' }}"> {!! Form::label('Member Name:') !!} {!! Form::text('name', old('name'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Name']) !!} {{ $errors->first('name') }}
has('email') ? 'has-error' : '' }}"> {!! Form::label('Member Email:') !!} {!! Form::text('email', old('email'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Email']) !!} {{ $errors->first('email') }}
has('comment') ? 'has-error' : '' }}"> {!! Form::label('Comment:') !!} {!! Form::textarea('comment', old('comment'), ['class'=>'Feedback form-control', 'placeholder'=>'Enter Member Comment']) !!} {{ $errors->first('comment') }}
{!! Form::close() !!}

email.blade.php

You received a comment from : {{ $name }}

Member Name: {{ $name }}

Member Email: {{ $email }}

Comment: {{ $user_comment }}

Laravel Sending the Email

php artisan make:mail 

first of all My account > Login as well as Security > Login to Google

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME= [email protected]
MAIL_PASSWORD= example.generated.app.password
MAIL_ENCRYPTION=tls

FeedbackUsController.php

validate($request, [ 'name' => 'required', 'email' => 'required|email', 'comment' => 'required' ]);
    Feedback::create($request->all()); 

    Mail::send('email',
       array(
           'name' => $request->get('name'),
           'email' => $request->get('email'),
           'user_comment' => $request->get('comment')
       ), function($comment)
   {
       $comment->from('[email protected]');
       $comment->to('[email protected]', 'Admin')->subject('Pakainfo Feedback');
   });

    return back()->with('success', 'Thanks for feedbacking us!'); 
   }
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple Laravel Contact Us Form With Email Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment