How To Create Contact Form With Validation-Php & Html

Create Contact Form With Php & Html

How To Create Contact Form -

Hello Friends Ajj Me Apko Btaunga  Ki Kis Prakar  Ham Apni Website Ke Liye Contact Form Bnana Sakta Hai.(By Using  Php Contact Form With Validation Script)

Contact Form Hmare Website Ke Liye Bhut He Jrruri Hota Hai.Contact Form Ke Help Se He User Apna Message Website Owner(Admin) Ko Bhej Sakte Hai.
Ajj Me Apko Btane Wala Hu Ki Kis Parkar Ham Contact Form Banakar Apne Website Me Add Kar Sakte Hai Or Apni Website Ke Liye Contact Form Bana Sakte Hai
Is Contact Form Me  Ham Php Mail Function() Ka Use Karege . Ab Jab Be Koi User Contact Form Me Apni Information ,Message Details Fill Karke Submit Karega To Uski Sare Information Website Admin Ke Email Id Par A Jaiyegi Jo Be Admin Dwara  Niche Diye Gye Code Me Setup Ki Hogi.

Used Language-
·         HTML
·         Jquery
·         Php
Yanha Html Ka Use Front End Banane Ke Liye Kiya  Gya Hai.
Jquery Ka Use Form Me Validation Banana  Ke Liye Kiya Gya Hai.
Php (Mail Function()) Ka Use Form Data To Email Id Par Send Karne Ke Liye Kiya Gya Hai

Php Mail Function Kya Hai-Mail Function() Ka Use Email Send Karne Ke Liye Kiya Jata Hai.Php Mail  Function Hame Directly Script Use Karke Email Send Karne Ka Feature Provide Karta Hai



contact form php -Index.php


<html>

<head>

<title> Contact Form</title>



</head>

<script>

function validateForm() {

     var x = document.forms["myForm"]["name"].value;

    if (x == "") {

        alert("name must be filled out");

        return false;

    }

    var x = document.forms["myForm"]["email"].value;

    if (x == "") {

        alert("email must be filled out");

        return false;

    }

     var x = document.forms["myForm"]["phone"].value;

    if (x == "") {

        alert("phone must be filled out");

        return false;

    }

var x = document.forms["myForm"]["message"].value;

    if (x == "") {

        alert("message must be filled out");

        return false;

    }

 

}

</script>

<body>

<center><h1>Simple Contact Form</h1></center>

<center><form name="myForm" action=""

onsubmit="return validateForm()" method="POST">







   Name <input type="text" name="name" placeholder="Enter Your Name" size="50%" value="" /><br>

    Email<input type="email" name="email" placeholder="Enter Your Email" size="50%" value=""/><br>

    Phone<input type="number" name="phone" placeholder="Enter Your phone" size="50%" value=""/><br>

 

   Message <textarea type="text" name="message" placeholder="Enter Your Message" size="50%" value=""></textarea>

     <input type="submit" name="submit" value="SUBMIT">

</form></center>

</body>

</html>



<?php

if(isset($_POST['submit'])){



       

           $name = ($_POST['name'])?$_POST['name']:'';

            $email = ($_POST['email'])?$_POST['email']:'';

             $phone = ($_POST['phone'])?$_POST['phone']:'';

            $message =($_POST['message'])?$_POST['message']:'';

         

          

         



            $to = 'bhupenderkashyap122@gmail.com';//enter Your email Id Here

            $subject = 'New contact form have been submitted';

            $htmlContent = "

                <h1>Contact request details</h1>

                <p><b>Name: </b>".$name."</p>

 

                    <p><b>Email: </b>".$email."</p>

                         <p><b>Phone: </b>".$phone."</p>

 

                <p><b>Message: </b>".$message."</p>

            ";

       

          $headers = "MIME-Version: 1.0" . "\r\n";

            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

          

            $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n";

          

            @mail($to,$subject,$htmlContent,$headers);

         

          

           echo 'Your contact request have submitted successfully.';

        }else{

      

         

        }

      

            

?>







Note- Aap Css And Bootstrap Ka Use Karke Is Contact Page Ko Mobile Responsive And Mobile Friendly Bana Sakte Hai.
Mail(To,Subject,Message,Headers,Parameters);
To-Required-Yanha Reciver Ke Email Id Enter Ki Jati Hai(Ye Field Mandatory(Jarruri) Hai)
Subject-Required-Yanha  Email Ka Subject Ata Hai (Mandatory Field)
Message-Required-Yanha Message Ko Define Kiya Jata Hai Jis Message Ko Hame Send Karna Hai
Header-Ye Optional Hai
Parameters-Optional

 Demo-  Contact Form

Is Parkar Aap Easily Contact Us Page Bana Sakte Hai.
Agar Apka Koi Sawal Ho To Aap Mujse Comment Me Puch Sakte Hai
Thank You
Team Gajabwap Web In Hindi
Also Read-

Previous
Next Post »

3 comments

Click here for comments
sam thakur
admin
26 April 2018 at 06:06 ×

nice code bro I like your website u always sharing best information about php

Reply
avatar
oliver
admin
24 September 2018 at 07:13 ×

I have also written a tutorial on create a custom php contact form here. Try out this script as well. You can also add validation or recaptcha to this script.

Reply
avatar
HubTech9
admin
13 April 2022 at 18:07 ×

If u want to sell your blog please contact
8955714398

Reply
avatar
Thanks for your comment