how to create contact us page without wordpress plugin

Sponsors

Every wordpress site is need to contact us page for there website or blog. All the people use the wordpress plugin for creating the contact us page. When you install the wordpress plugin that will install some extra code to your wordpress site. After using wordpress plugin you need some customization in that plugin due to UI. You need R&D time and development time.

In this article I will show how you can create the contact us page with out any wordpress plugin. Using following code you can create the contact us form very easily.

First create contact-us.php page in your wordpress theme folder and put 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]).">\r\nReply-To:".trim($_POST[your_email]));
 }
}
?>
<?php get_header(); ?>
<div id="container">
 <div id="content" role="main">
 <?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 = "Send email" /></div>
 </div>

 </form>
 <?php } ?>
 </div><!-- .entry-content -->
 </div><!-- #post-## -->
 <?php endwhile; ?>
 </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Then go to your wordpress admin panel. Create page called contact us. In Right side panel you will find the “page attribute” section. From template drop down choose the Contact Us option. and create the contact us page.

WordPress uses the wp_mail() function for sending the email. all wordpress plugin also use the wp_mail() function for sending the email.

If you are having issues with sending the email with this function then you should use the different SMTP mail server for sending mail.

For sending email through SMTP  in detail you should check the following article.

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

With this code you can write your own CSS for styling the contact form as per your wordpress theme. If you are having any issues or question about this script then please write to me.

Incoming search terms:

You may like following Articles!

29 thoughts on “how to create contact us page without wordpress plugin

  1. Howdy. Great work once again. I enjoyed reading your blog for the reason that the writers often post great pieces of information. Awesome article.I plan to add this blog to my faves. I am planning to subscribe to the blog feed too. Just got a brand new cell too. Does anyone own the galaxy??? It is awesome..

  2. Could I make a suggestion? I do think youve got something great here. But what if you also offered a few references towards a site which supports what you are saying? Or perhaps you may give us some extra information to look at, whatever would connect what you were saying, something more concrete?

  3. I revelled reading it. I require to read more on this subject…I am admiring the time and effort you put in your blog, because it is apparently one great place where I can find lot of reusable info..

  4. 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!

  5. Thanks for sharing this article. But it would have been great if you could have shared how exactly the “Contact Us” page will look. And will i need to write something also while i am creating the page ?

  6. Hi Dear, I have followed your steps in my localhost wordpress admin… But i cant able to send a mail… I think it sould be work in server only….

    • I cannot able to send email from windows box. You need sendmail server on your machine or you need to install send-smtp-email-wordpress-plugin

      • hello dear i am also use wp_mail in contact-us.php file… But i don’t know why i cant able to send an email to admin…. Here i echo all the values in wp_mail(values) but i didn’t echo wp_mail()…. please anyone help me…

Leave a Reply