How to create contact us template page in wordpress

Contact us page is important for every website. Many wordpress developers use the contact7 wordpress plugin for creating the contact page.

Dont use the plugins for contact us page in wordpress

If you use any contact us plugin then your site became little bit slow. because due to database custom quires you will some bandwidth.  My suggestion is use simple php code for that.

You need to just create the contact.php page in your wordpress theme folder and put the following code in that file.

Template Name: Contact Us
 $error = "";
 $error .= "<p>Please enter your name</p>";
 $error .= "<p>Please enter a valid email address</p>";
 $error .= "<p>Please enter a message</p>";
 $error .= "<p>Please enter a message</p>";
 $email = wp_mail(get_option("admin_email"),trim($_POST[your_name])." sent you a message from ".get_option("blogname"),stripslashes(trim($_POST[your_message])),"From: ".trim($_POST[your_name])." <".trim($_POST[your_email]).">\r\nReply-To:".trim($_POST[your_email]));
<?php get_header(); ?>

 <section id="primary">
 <div id="content" role="main">

<div id="archives">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <h1><?php the_title(); ?></h1>
 <?php if($email){ ?>
 <p><strong>Message succesfully sent. I'll reply as soon as I can</strong></p>
 <?php } else { if($error) { ?>
 <p><strong>Your messange hasn't been sent</strong><p>
 <?php echo $error; ?>
 <?php } else { the_content(); } ?>
 <form action="<?php the_permalink(); ?>" id="contact_me" method="post">
 <input type="hidden" name="sent" id="sent" value="1" />
 <div id="form">
 <div id="lebel">Your Name (required)</div>
 <div id="input-field"><input type="text" name="your_name" id="your_name" value="<?php echo $_POST[your_name];?>" /></div>
 <div id="lebel">Your Email (required)</div>
 <div id="input-field"><input type="text" name="your_email" id="your_email" value="<?php echo $_POST[your_email];?>" /></div>
 <div id="lebel">Subject</div>
 <div id="input-field"><input type="text" name="your_subject" id="your_subject" value="<?php echo $_POST[your_subject];?>" /></div>
 <div id="lebel">Your Message(required)</div>
 <div id="input-field"><textarea name="your_message" id="your_message"><?php echo stripslashes($_POST[your_message]); ?></textarea></div>
 <div id="lebel"> </div>
 <div id="input-field"><input type="submit" name = "send" value = "Contact Us" /></div>

 <?php } ?>
 </div><!-- .entry-content -->
 </div><!-- #post-## -->
 <?php endwhile; ?>

 </div><!-- #content -->
 </section><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

If you need more information about then check following articles.

You may like following Articles!

  • John

    Great wordpress hack for creating contact us page

  • Alveo

    I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.

  • Leanne Shulthess

    Intriguing post. I have been searching for some good resources for solar panels and discovered your blog. Planning to bookmark this one!

  • Arlie Breedon

    Of course, what a great site and informative posts, I will add backlink – bookmark this site? Regards, Reader

  • TheMannyMan

    How do I send this information to a databse instead – basically I would like to send to database, receive a notification and also send email to the person that contact me. Could this be achieved at one go? Thanks!

  • Tifany Harlan

    Interesting read, perhaps the best article iv’e browse today. We learn everyday cheers to you!

  • simon

    this works great thank you, but in the boxes appears the code. how do i stop the code form shoing the the boxes?

  • lorenzo

    Hi Folks! Here, there’s a list of 9 Template Page including the one in this post!