Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Contact
- */
- ?>
- <?php
- if(isset($_POST['submitted'])) {
- if(trim($_POST['Name']) === '') {
- $nameError = 'Please enter your name.';
- $hasError = true;
- } else {
- $name = trim($_POST['Name']);
- }
- if(trim($_POST['email']) === '') {
- $emailError = 'Please enter your email address.';
- $hasError = true;
- } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
- $emailError = 'You entered an invalid email address.';
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- if(trim($_POST['message']) === '') {
- $messageError = 'Please enter a message.';
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $message = stripslashes(trim($_POST['message']));
- } else {
- $message = trim($_POST['message']);
- }
- }
- if(!isset($hasError)) {
- $emailTo = get_option('tz_email');
- if (!isset($emailTo) || ($emailTo == '') ){
- $emailTo = get_option('admin_email');
- }
- $subject = '[PHP Snippets] From '.$name;
- $body = "Name: $name \n\nEmail: $email \n\nMessage: $message";
- $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
- mail($emailTo, $subject, $body, $headers);
- $emailSent = true;
- }
- } ?>
- <?php get_header(); ?>
- <div id="content">
- <?php the_post() ?>
- <div id="post-<?php the_ID() ?>" class="post">
- <div class="entry-content">
- <?php if(isset($emailSent) && $emailSent == true) { ?>
- <div class="thanks">
- <p>Thanks, your email was sent successfully.</p>
- </div>
- <?php } else { ?>
- <?php the_content(); ?>
- <?php if(isset($hasError) || isset($captchaError)) { ?>
- <p class="error">Sorry, an error occurred.<p>
- <?php } ?>
- <div id="contactform">
- <h2>Contact Me</h2>
- <form id="query" class="clearfix" action="<?php the_permalink(); ?>" method="post" name="query">
- <div id="results"></div><!--end results-->
- <div id="fields">
- <p>
- <label>Name<span class="error">*</span></label>
- <input type="text" name="email" id="email" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" />
- <?php if($nameError != '') { ?>
- <span class="error"><?=$nameError;?></span>
- <?php } ?>
- </p>
- <p>
- <label>Email<span class="error">*</span></label>
- <input type="text" name="phone" id="phone" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" />
- <?php if($emailError != '') { ?>
- <span class="error"><?=$emailError;?></span>
- <?php } ?>
- </p>
- <p>
- <label>Subject</label>
- <input type="text" name="name" id="name" value="" />
- </p>
- <p>
- <label>Message<span class="error">*</span></label>
- <textarea name="message" cols="2" rows="2" id="msg"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
- <?php if($commentError != '') { ?>
- <span class="error"><?=$commentError;?></span>
- <?php } ?>
- </p>
- <button type="submit" name="submit" id="send">Send</button>
- <p><!--Spam Bot-->
- <label class="hidden">Surname</label>
- <input name="Surname" type="text" name="submitted" id="submitted" class="hidden" value=""/>
- </p><!--End Spam Bot-->
- </div><!--end fields-->
- </form>
- <?php } ?>
- </div><!--end contactform-->
- </div><!-- .entry-content ->
- </div><!--end post-->
- </div><!--end content-->
- <?php include (TEMPLATEPATH . '/sidebar_contact.php'); ?>
- </div><!--end container-->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement