Advertisement

How to Create PHP validation Contact Form in Few Simple Step? - Chinaitechghana

China iTech Ghana
Sunday, May 9, 2021 | views Last Updated 2021-05-09T19:55:50Z

Are you want to Create a PHP Validation contact form? This form helps to send Your message, and email address to other Gmail account successfully. If you already familiar with HTML, CSS, and MYSQL then this PHP validation contact form you can easily create with some simple instruction.


There are many ways to create working contact using a different programming language such as Node JS, Python, C++, and others. You don't need to create a responsive contact page just your message should successfully send to your Email friend.


One important thing that your PHP contact form doesn't work in localhost, You must upload your PHP contact form to the online Server or using XAMPP help to create a local server on Your computer.


How to Download and Use XAMPP?

After sending Create Your Contact form, You must know how to use XAMPP local server. Here is some step about download and use of XAMPP in your PC.

  • Go to Google Chrome and Search for XAMPP install.
  • Choose to operate the system and install a new version of XAMPP.
  • Exact file after download and click next next next.
  • The open XAMPP control panel then start  apache and MySQL 
  • Finally, You Go to Google chrome and search for localhost/dashboard
  • Now, You can create a new database and table to upload your PHP code.

After Install and setup your  XAMPP c Panel, Here we provide Some steps to Create your PHP working contact form, and Any visitor comes to your website and you get your Name, Email, Massage successfully. Copy this HTML, PHP, and  CSS code and Upload your Localhost server.


Step 1. First, create an index.php document and paste This code.  This document design your layout and some PHP function


<!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>';
                                                f(isset($_GET['success']))
                         
                         $Msg = " Your Message Has Been Sent ";
                            echo '<div class="alert alert-success">'.$Msg.'</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>

 Step: 2: After copy this index.php document you should create another mail.php file where this PHP help to send a message.

<?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 completely create these two files index.php and mail.PHP file, now you can upload the file to the Localhost server or any other online server. This is the complete and best way to create any form easily. If anyone can send a message without fill information then it shows the error in filling in information. 

Enter Your Email Address to Recieve Our Latest Updates:

Delivered by Chinaitechghana.com

Comments
comments that appear entirely the responsibility of commentators as regulated by the ITE Law
  • How to Create PHP validation Contact Form in Few Simple Step? - Chinaitechghana

Trending Now

Recents

Advertisement