Advertisement
Guest User

Untitled

a guest
Sep 16th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Contact
  4. */
  5. ?>
  6.  
  7. <?php
  8. if(isset($_POST['submitted'])) {
  9. if(trim($_POST['Name']) === '') {
  10. $nameError = 'Please enter your name.';
  11. $hasError = true;
  12. } else {
  13. $name = trim($_POST['Name']);
  14. }
  15.  
  16. if(trim($_POST['email']) === '') {
  17. $emailError = 'Please enter your email address.';
  18. $hasError = true;
  19. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  20. $emailError = 'You entered an invalid email address.';
  21. $hasError = true;
  22. } else {
  23. $email = trim($_POST['email']);
  24. }
  25.  
  26. if(trim($_POST['message']) === '') {
  27. $messageError = 'Please enter a message.';
  28. $hasError = true;
  29. } else {
  30. if(function_exists('stripslashes')) {
  31. $message = stripslashes(trim($_POST['message']));
  32. } else {
  33. $message = trim($_POST['message']);
  34. }
  35. }
  36.  
  37. if(!isset($hasError)) {
  38. $emailTo = get_option('tz_email');
  39. if (!isset($emailTo) || ($emailTo == '') ){
  40. $emailTo = get_option('admin_email');
  41. }
  42. $subject = '[PHP Snippets] From '.$name;
  43. $body = "Name: $name \n\nEmail: $email \n\nMessage: $message";
  44. $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  45.  
  46. mail($emailTo, $subject, $body, $headers);
  47. $emailSent = true;
  48. }
  49.  
  50. } ?>
  51.  
  52. <?php get_header(); ?>
  53.  
  54. <div id="content">
  55.  
  56. <?php the_post() ?>
  57. <div id="post-<?php the_ID() ?>" class="post">
  58. <div class="entry-content">
  59.  
  60. <?php if(isset($emailSent) && $emailSent == true) { ?>
  61. <div class="thanks">
  62. <p>Thanks, your email was sent successfully.</p>
  63. </div>
  64. <?php } else { ?>
  65. <?php the_content(); ?>
  66. <?php if(isset($hasError) || isset($captchaError)) { ?>
  67. <p class="error">Sorry, an error occurred.<p>
  68. <?php } ?>
  69. <div id="contactform">
  70. <h2>Contact Me</h2>
  71.  
  72. <form id="query" class="clearfix" action="<?php the_permalink(); ?>" method="post" name="query">
  73. <div id="results"></div><!--end results-->
  74. <div id="fields">
  75. <p>
  76. <label>Name<span class="error">*</span></label>
  77. <input type="text" name="email" id="email" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" />
  78. <?php if($nameError != '') { ?>
  79. <span class="error"><?=$nameError;?></span>
  80. <?php } ?>
  81. </p>
  82. <p>
  83. <label>Email<span class="error">*</span></label>
  84. <input type="text" name="phone" id="phone" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="required requiredField email" />
  85. <?php if($emailError != '') { ?>
  86. <span class="error"><?=$emailError;?></span>
  87. <?php } ?>
  88. </p>
  89. <p>
  90. <label>Subject</label>
  91. <input type="text" name="name" id="name" value="" />
  92. </p>
  93. <p>
  94. <label>Message<span class="error">*</span></label>
  95. <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>
  96. <?php if($commentError != '') { ?>
  97. <span class="error"><?=$commentError;?></span>
  98. <?php } ?>
  99. </p>
  100.  
  101. <button type="submit" name="submit" id="send">Send</button>
  102.  
  103. <p><!--Spam Bot-->
  104. <label class="hidden">Surname</label>
  105. <input name="Surname" type="text" name="submitted" id="submitted" class="hidden" value=""/>
  106. </p><!--End Spam Bot-->
  107.  
  108. </div><!--end fields-->
  109. </form>
  110. <?php } ?>
  111. </div><!--end contactform-->
  112. </div><!-- .entry-content ->
  113. </div><!--end post-->
  114.  
  115. </div><!--end content-->
  116.  
  117. <?php include (TEMPLATEPATH . '/sidebar_contact.php'); ?>
  118. </div><!--end container-->
  119. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement