How to Make Contact US Form In Php With Mail

0

When You will 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 Contact US Form in Php With 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 Email Using Contact Us Form in Php.

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

You May Also Like: Student Registration System in Php

Contact US Form In Php With Mail

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, If you want to learn How to Buy Hosting and Domain Please Watch my Video.

How To Buy Domain Name And Web Hosting

Once you Buy Web Hosting and Domain Name, you will be able to upload any Php-based Project or You can create a website and upload it with a live server or Online Server.

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 Contact Us Form in Php, and Also You will be able to design it. First of All, You need to Download Bootstrap CSS File, which helps you to design Contact Us Form.

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

Then you need to Copy the below script and paste 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, then you need to include another Php file, 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 = "[email protected]";

           if(mail($to,$Subject,$Msg,$Email))
           {
               header("location:index.php?success");
           }
       }
    }
    else
    {
        header("location:index.php");
    }
?>

Once you use those file 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 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.