Email Form - Simple PHP Enquiry Mail Form

This is one of the simple enquiry form. This is one of the easiest method and also very simple to create with the help of html and php. All the company looking for generate leads from website. So this enquiry form is very important to communicate with the clients. Now will see how to create this simple web form. The form is looks like below image, you can add field and delete the unwanted fields according to your business.

Html form design for Email Enquiry:

The below code is just simple html file. This form is used to capture information from customers. You can add and remove the fields below according to your requirement. And also design the form using css. This is just a form to get data from the user. you can name it as a enquiry.html or index.html. When you submit this form it calls the mail1.php file.


<!doctype html>
<html lang="en">
<title>Simple Enquiry form using html and php mail function</title>
<h1>Simple Enquiry form using html and php mail function</h1>
<p>This is one of the simple demo for enquiry form. It will done by using the php mail function and html form. </p>
<div class="enq-div">
<form id="contact-form1" class="contact-form flex-type" action="mail1.php" method="post">
<p><input type="text" name="name"  required placeholder="Your Name (required)"></p>
<p><select name="enquiry-abt">
<option name="Enquiry About Admission" value="Enquiry About Admission" >Enquiry About Admission</option>
<option name="Enquiry About Fees" value="Enquiry About Fees" >Enquiry About Fees</option>
<option name="Others" value="Others" >Others</option>
<p><input type="email" name="email" required placeholder="Email (required)"></p>
<p><input type="text" name="subject" required placeholder="Subject"></p>
<p><input type="Mobile" name="mobile" required placeholder="Mobile Number"></p>
<p><textarea rows="8" name="message" required placeholder="Message"></textarea></p>
<p><input type="submit" name="submit" required value="submit" class="btn" data-type="submit"></button></p>
<h5><a href=""></a></h5>

Css code to design the Enquiry web form

 This css helps you to design the plain html form as stylish one. You can design the form according to your choice or just add the below css code to your webpage to design the plain html form .

border:1px solid green;

border:1px solid green;
padding-top: 0px;
padding-bottom: 0px;

border:1px solid green;
border:1px solid green;
margin:0 auto;

width:260px !important;

Php code to get the data from the enquiry form and mail those information to provided Email

This is simple php code to get the form data and stored it to the particular variable and then sent those form information to the Email id using php mail() function, this php code will execute after submit the form so i provided the condition if(isset($_POST['submit'])). Then i provided to and from email as a , You should change those email ids. But this email id should be domain based email id. Because the php mail function needs domain based email in the from field and you can use to mail id whatever you want like (gmail, yahoomail etc...). Some cases it won't work better you can use both from and to address as a domain based email.

Then i get the user form information using php and stored it in the particular variable and then i called all the variables with the label and i stored this into message variable. finally i used mail function and called the necessary variable like From,to, subject, message and headers2 the mail function like mail($to,$subject,$message,$headers2). Then i given alert box to display the success message and redirect location with the help of javascript. I am not given any validation in this particular form.

The message will goes to the to email id inbox in some cases it goes to the spam box, Check both inbox and spam folder. If you given same domain based  email id (official mail id) then message will comes to your Email inbox. you can download the full Code of php enquiry mail form here. and check the Demo enquiry  form here.


    $to = ""; 
    $from = ""; 
    $name = $_POST['name'];
    $enquiry = $_POST['enquiry-abt'];
    $email = $_POST['email'];
$subject1 = $_POST['subject'];
$mobile = $_POST['mobile'];
$message = $_POST['message'];
    $subject = "New Enquiry From Website";
    $message = " \n\n Name:".$name ."\n\n Enquiry About:".$enquiry . "\n\n Email : " . $email ."\n\n Subject :".$subject1."\n\n Mobile :".$mobile."Message".$message. "\n\n" ;
    $headers2 = "Feedback From Website: " . $email;
echo '<script>alert("Your Enquiry Received . We will contact you soon...");</script>';
echo '<script>location.href = "index.php"</script>';

You can received the email like below image:


you can use this enquiry form as a feedback form, contact form, etc. Because it is used send the email with form details. I hope this post is very useful.

Post a Comment