How to Make Contact US Form In Php With Mail

How to Make Contact US Form In Php With Mail

When You build an application using Php and MySQLi or using another method, you must include the Contact Us From, because It’s very important to contact visitors with the website author.

Visitors are visiting your site and contact you with the help of the Contact Us form. If you want to learn How to Make a Contact US Form in PHP with the Mail Function, I will teach you How You can write the codes to make a Contact Us form in PHP, and also you will learn how to Send an Email Using the Contact Us Form in Php.

First of All, You must design the Contact Us form, If you have ideas or knowledge about HTML5, CSS3, or Bootstrap you can use that to design the Contact Us form. In this tutorial, I’m going to show you How You can use Bootstrap to Design a Responsive Contact Us Form.

You May Also Like: Student Registration System in Php

One important thing Php Mail function doesn’t work on localhost, you must upload your project or contact us from with Online Server or Cpanel. If you have a Domain Name and Web Hosting that’s great. otherwise, you need to get it.

How to Send HTML Form Data to Email using Php

Here are a few things you need to follow, then you will be able to create a Contact Us Form in Php, and Also You will be able to design it. First of All, You need to Download the Bootstrap CSS File, which helps you to design the Contact Us Form.

You May Also Like: Login & Registration System with Email Activation

Then you need to Copy the below script and paste it into your own project. The FileName is INDEX.PHP

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="bootstrap.css">
    <title>Contact Us Form In Php</title>
</head>
<body>
<div class="container">
        <div class="row">
            <div class="col-lg-6 m-auto">
                <div class="card mt-5">
                    <div class="card-title">
                        <h2 class="text-center py-2"> Contact Us </h2>
                        <hr>
                        <?php 
                            $Msg = "";
                            if(isset($_GET['error']))
                            {
                                $Msg = " Please Fill in the Blanks ";
                                echo '<div class="alert alert-danger">'.$Msg.'</div>';
                            }
                            if(isset($_GET['success']))
                            {
                                $Msg = " Your Message Has Been Sent ";
                                echo '<div class="alert alert-success">'.$Msg.'</div>';
                            }

                        ?>
                    </div>
                    <div class="card-body">
                        <form action="process.php" method="post">
                            <input type="text" name="UName" placeholder="User Name" class="form-control mb-2">
                            <input type="email" name="Email" placeholder="Email" class="form-control mb-2">
                            <input type="text" name="Subject" placeholder="Subject" class="form-control mb-2">
                            <textarea name="msg" class="form-control mb-2" placeholder="Write The Message"></textarea>
                            <button class="btn btn-success" name="btn-send"> Send </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body></html>

Once use that, you need to include another Php file, and then your project will be ready to use. Here is another PROCESS.PHP File.

You May Also Like: Insert Update Delete In Php

<?php 

if(isset($_POST['btn-send']))
    {
       $UserName = $_POST['UName'];
       $Email = $_POST['Email'];
       $Subject = $_POST['Subject'];
       $Msg = $_POST['msg'];
       if(empty($UserName) || empty($Email) || empty($Subject) || empty($Msg))
       {
           header('location:index.php?error');
       }
       else
       {
           $to = "admin@onlineittuts.com";
           if(mail($to,$Subject,$Msg,$Email))
           {
               header("location:index.php?success");
           }
       }
    }
    else
    {
        header("location:index.php");
    }
?>

Once you use those files then your Contact Us Form In php with Mail Function is ready. You can use that with your project. If you want to learn How You can design and also develop a Contact Us Form in Php, You can watch my video tutorial. That helps you to design and also develop the Contact Us Form Using Php with Mail Function.

You May Also Like: Upload Php Website on Cpanel

How to Make Contact US Form In Php With Mail

Guys, I hope you have learned something new. If you like it, kindly share the content and Share it with Social Networks. If you have any questions/suggestions, comment to me or email, me after receiving your email. I will help you to solve your problems. Thanks For Watching and Reading the Complete Article.