Dont use the plugins for contact us page in wordpress which will and unwanted code to your site.we given the simple code snippet for create contact us template page in wordpress.

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.


<?php
/*
Template Name: Contact Us
*/
if($_POST[sent]){
 $error = "";
 if(!trim($_POST[your_name])){
 $error .= "<p>Please enter your name</p>";
 }
 if(!filter_var(trim($_POST[your_email]),FILTER_VALIDATE_EMAIL)){
 $error .= "<p>Please enter a valid email address</p>";
 }
 if(!trim($_POST[your_message])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!trim($_POST[your_subject])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!$error){
 $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]).">rnReply-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>
 <div>
 <?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>
 </div>

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

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

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

create contact us template page in wordpress

create contact us template page in wordpress

 

 

If you need more information about then check following articles.

http://wordpressapi.com/create-contact-page-wihout-wordpress-plugin/

http://wordpressapi.com/send-smtp-email-wordpress-plugin/

Written by Purab Kharat

I Purab am from Pune. I worked as WordPress and Drupal Architect and consultant. I worked on many technologies like Wordpress, Drupal, Ruby on Rails, Flex, PHP, jQuery etc... Senior Technical Lead at Smartsourcing Global Pvt Ltd in Princeton, NJ, USA.I contributor of many wordpress plugins and Drupal Modules. I am core developer of Drupal.Connect to purab on LinkedIn or Follow @purab on Twitter or Follow me on Google+ or Write Mail to purabdk@gmail.com or Chat with me on Skype : purabdk

This article has 3 comments

  1. TheMannyMan Reply

    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!

  2. simon Reply

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

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>