Note: make a file contact_form.php and paste the below code.

<?php
/*
Template Name: contact_form
*/
?>
<?php get_header(); ?>
 
<div id="content" class="narrowcolumn">
<!-- replaced contact start here -->
<span class="breadcrumbs"><a href="<?php echo get_option('home'); ?>/">Home</a> </span>
  <h2 class="title">Contact Us</h2>
  <?php
if(isset($_POST['Submit'])){ //check if user submitted the contact form
$error="";
 if($_POST['contact_name']=='')$error.="Name required.<br/>";
 if($_POST['contact_email']=='')$error.="Email required.<br/>";
 if($_POST['contact_phone']=='')$error.="Phone  required.<br/>";
 if($_POST['contact_comment']=='')$error.="Comment required.<br/>";
if($error!=""){
 //if any errors skip mailing and display the errors for users.
 echo "<span style='color:red'>$error</span>";
}else{
 // get admin email from wordpress default options
 $to=get_option('admin_email');
 $subject="One contact enquire at noblefligh re: ".$_POST['contact_reason'];
 $body="rn Hi Admin";
 $body.="rn You had an enquiry:";
 $body.="rn Regarding:t".$_POST['contact_reason'];
 $body.="rn Name: t".$_POST['contact_name'];
 $body.="rn Email: t".$_POST['contact_email'];
 $body.="rn Phone:t".$_POST['contact_phone'];
 $body.="rn Comment: rn ".$_POST['contact_comment'];
 // wordpress default handy mail function
 wp_mail( $to, $subject, $body);
 echo "<span style='color:green;'>your comment sent to admin successfully</span>";
 // display success message.
}
 
}
 ?>
  <form id="contact_form" name="contact_form" method="post" action="<?php echo the_permalink(); ?>">
    <table border="0">
      <tr>
        <td>About </td>
        <td><select name="contact_reason" id="contact_reason" style="width:145px;">
            <option value="Product">Product</option>
            <option value="Service">Service</option>
            <option value="Other">Other</option>
          </select>
        </td>
      </tr>
      <tr>
        <td>Name</td>
        <td><input name="contact_name" type="text" id="contact_name" style="width:145px" /></td>
      </tr>
      <tr>
        <td>Email</td>
        <td><input name="contact_email" type="text" id="contact_email" style="width:145px" /></td>
      </tr>
      <tr>
        <td>Phone</td>
        <td><input name="contact_phone" type="text" id="contact_phone" style="width:145px" /></td>
      </tr>
      <tr>
        <td>Comment</td>
        <td><textarea name="contact_comment" id="contact_comment" style="width:300px"></textarea></td>
      </tr>
      <tr>
        <td colspan="2" align="center"><input type="submit" name="Submit" value="Submit" />
          <input type="reset" name="Submit2" value="Reset" /></td>
      </tr>
    </table>
  </form>
<!-- replaced content end here -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Back To Top