Hi friends Hello today I am going to tell you how to create html contact form, and I will also tell about its backend php code that the backend of php works with our html bootstrap.
So friends, we start with this, first of all we have to create a normal html form which we will connect with our php backend, whatever data will be put inside the form, that data on our gmail or any other mail you data Can get Let’s start the first step.
Step 1
contact.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | <!-- Contact form --> <form action="new.php" method="post" class="form" role="form"> <!-- Form Field --> <div class="form-group"> <input class="form-control required" id="name" name="name" placeholder="Name" type="text" required=""> </div> <!-- /Form Field --> <!-- Form Field --> <div class="form-group"> <input class="form-control required" id="email" name="email" placeholder="Email" type="email" required=""> </div> <!-- /Form Field --> <!-- Form Field --> <div class="form-group"> <input class="form-control required" id="phone" type="text" name="phone" placeholder="phone" required=""> </div> <!-- /Form Field --> <!-- Form Field --> <div class="form-group"> <input class="form-control required" id="subject" type="text" name="subject" placeholder="Subject" required=""> </div> <!-- /Form Field --> <!-- Form Field --> <div class="form-group"> <textarea class="form-control required" id="message" name="message" placeholder="Message" rows="5" required=""></textarea> </div> <!-- /Form Field --> <!-- Form Field --> <div class="form-group"> <input type="submit" class="btn btn-default form-send" value="submit"> </div> <!-- /Form Field --> </form> <!-- /Contact Form --> |
Friends, you saw that our html form is ready and we have validated it, so we will not use id here in our php backend, we will use name like name = “email”, and name = “subject” We are going to use etc here, let’s start php backend coding.
Step 2
new.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?php $subject = "enquiry"; $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone'] ; $subject = $_POST['subject'] ; $message = $_POST['message'] ; $headers = "From: $email"; $headers1 = "Name: $name \n Email: $email \n Phone: $phone \n Subject: $subject \n Messages: $message "; $sent = mail($to, $subject, $headers1 ,$headers ) ; if($sent) { header ("Location:index.html"); } else {print "We encountered an error sending your mail"; } ?> |
Here you are all seeing how we have kept php backend code but you can also keep it in the same way, friends, if you have any kind of problem then you can ask us by making comments.