Advertisement
keihead

newcf

Jul 19th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.51 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Contact
  4. */
  5. ?>
  6. <?php
  7.     //If the form is submitted
  8.     if(isset($_POST['submitted'])) {
  9.      
  10.      
  11.     //Check to see if the honeypot captcha field was filled in
  12.     if(trim($_POST['checking']) !== '') {
  13.             $captchaError = true;
  14.     } else {
  15.            
  16.     //Check to make sure that the name field is not empty
  17.             if(trim($_POST['contactName']) === '') {
  18.                     $nameError = 'You forgot to enter your name.';
  19.                     $hasError = true;
  20.             } else if(strlen($_POST['contactName']) < 3) {
  21.                     $nameError = 'The name must be at least 3 characters long.';
  22.                     $hasError = true;
  23.             } else {
  24.                     $name = trim($_POST['contactName']);
  25.             }
  26.            
  27.     //Check to make sure sure that a valid email address is submitted
  28.             if(trim($_POST['email']) === '')  {
  29.                     $emailError = 'You forgot to enter your email address.';
  30.                     $hasError = true;
  31.             } else if (!eregi("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", trim($_POST['email']))) {
  32.                     $emailError = 'You entered an invalid email address.';
  33.                     $hasError = true;
  34.             } else {
  35.                     $email = trim($_POST['email']);
  36.             }
  37.                    
  38.     //Check to make sure a subject was entered    
  39.             if(trim($_POST['subject']) === '') {
  40.                     $subjectError = 'You forgot to enter a subject.';
  41.                     $hasError = true;
  42.             } else if(strlen($_POST['subject']) < 3) {
  43.                     $subjectError = 'The subject must be at least 3 characters long.';
  44.                     $hasError = true;
  45.             } else {
  46.                     if(function_exists('stripslashes')) {
  47.                             $subject = stripslashes(trim($_POST['subject']));
  48.                     } else {
  49.                             $subject = trim($_POST['subject']);
  50.                     }
  51.             }
  52.            
  53.     //Check to make sure comments were entered    
  54.             if(trim($_POST['comments']) === '') {
  55.                     $commentError = 'You forgot to enter your comments.';
  56.                     $hasError = true;
  57.             } else {
  58.                     if(function_exists('stripslashes')) {
  59.                     $comments = stripslashes(trim($_POST['comments']));
  60.                     } else {
  61.                             $comments = trim($_POST['comments']);
  62.                     }
  63.             }
  64.               // SAVE INFO AS COOKIE, if user wants name and email saved
  65.                 $save = $_POST['save-stuff'];
  66.                 if ($save == true) {
  67.                     setcookie("name", $_POST['name'], time()+60*60*24*365);
  68.                     setcookie("email", $_POST['email'], time()+60*60*24*365);
  69.                 }
  70.  
  71. //If there is no error, send the email
  72.     if(!isset($hasError)) {
  73.  
  74.         $emailTo = 'keysarrr@gmail.com';
  75.         $subject = $subject;
  76.         $sendCopy = trim($_POST['sendCopy']);
  77.         $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
  78.         $headers .= "MIME-Version: 1.0\r\n";
  79.         $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  80.         $body = '<html><body>';
  81.         $body .= '<div align="center" style="width: 600px; color: #000; margin: 0 auto; padding: 20px; ">';
  82.         $body .= '<img src="http://keihead.com/test/images/ks_email_header.png" />';
  83.         $body .= '<h1 style="color: #000;">Contact Form</h1>';
  84.         $body .= '<ul style="list-style: none; text-align: left;">
  85.                   <li><strong>Name:</strong> '.$name.'</li>
  86.                   <li><strong>Email:</strong> <em style="color: #FFF;">'.$email.'</em></li>
  87.                   <li style="border-bottom: 2px solid #FF0000;"><strong>Subject:</strong> '.$subject.'</li>
  88.                   <li>'.$comments.'</li>
  89.                   </ul>';
  90.         $body .= '</div>';
  91.         $body .= "</body></html>";
  92.         mail($emailTo, $subject, $body, $headers);
  93.  
  94.        
  95.             $headers = "From: Keisa L. <noreply@keihead.com>\r\n";
  96.             $headers .= "MIME-Version: 1.0\r\n";
  97.             $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  98.             $body = '<html><body>';
  99.             $body .= '<div align="center" style="width: 600px; color: #000; margin: 0 auto; padding: 20px; ">';
  100.             $body .= '<img src="http://keihead.com/test/images/ks_email_header.png" />';
  101.             $body .= '<h1 style="color: #000; font-style: italic;">Thanks for contacting us!</br> We&#39;ll get back to you as soon as possible.</h1>';
  102.             $body .= "Here is a copy of the email you recently sent us:";
  103.             $body .= '<ul style="list-style: none; text-align: left;">
  104.                       <li><strong>Name:</strong> '.$name.'</li>
  105.                       <li><strong>Email:</strong> <em style="color: #FFF;">'.$email.'</em></li>
  106.                       <li style="border-bottom: 2px solid #FF0000;"><strong>Subject:</strong> '.$subject.'</li>
  107.                       <li>'.$comments.'</li>
  108.                       </ul>';
  109.             $body .= '</div>';
  110.             $body .= "</body></html>";
  111.             mail($email, $subject, $body, $headers);
  112.        
  113.  
  114.         $emailSent = true;
  115.  
  116.         }
  117.     }
  118. } ?>
  119.  
  120. <?php get_header('header2'); ?>
  121.  
  122. <div id="container" class="clearfix">
  123.     <div class="page-title">
  124.         <h1 class="title">
  125.             <span class="ico-music left FF0000"></span>
  126.             <?php wp_title('');?>
  127.         </h1>
  128.         <span class="diag-title"></span>
  129.     </div>
  130.    
  131. <div id="left-content">
  132. <?php if(isset($emailSent) && $emailSent == true) { ?>
  133.  
  134. <div class="thanks">
  135.     <h1>Thanks <?=$name;?>,</h1>
  136.     <p>Your email was successfully sent.</br> Please allow up to 24 hours for a response.</p>
  137. </div>
  138.  
  139. <?php } else { ?>
  140. <?php if (have_posts()) : ?>       
  141. <?php while (have_posts()) : the_post(); ?>
  142.  
  143. <form action="" id="contactForm" method="post">    
  144. <ol class="forms">
  145.     <li>
  146.         <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>" class="requiredField" placeholder="Name" />
  147.         </br>
  148.         <?php if($nameError != '') { ?>
  149.         <span class="error"><?=$nameError;?></span>
  150.         <?php } ?>
  151.     </li>
  152.                    
  153.     <li>
  154.         <input type="text" name="email" id="email" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" class="requiredField email" placeholder="Email" />
  155.         </br>
  156.         <?php if($emailError != '') { ?>
  157.         <span class="error"><?=$emailError;?></span>
  158.         <?php } ?>
  159.     </li>
  160.                    
  161.     <li>
  162.         <input type="text" name="subject" id="subject" value="<?php if(isset($_POST['subject']))  echo $_POST['subject'];?>" class="requiredField subject" placeholder="Subject" />
  163.         <br/>
  164.         <?php if($subjectError != '') { ?>
  165.         <span class="error"><?=$subjectError;?></span>
  166.         <?php } ?>
  167.     </li>
  168.                    
  169.     <li class="textarea">
  170.         <textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField" placeholder="Type your message here..."><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
  171.         </br>
  172.         <?php if($commentError != '') { ?>
  173.         <span class="error"><?=$commentError;?></span>
  174.         <?php } ?>
  175.     </li>
  176.    
  177.     <li class="inline">
  178.         <input type="checkbox" name="save-stuff" value="yes"<?php if(isset($_POST['save-stuff']) && $_POST['save-stuff'] == "yes") { echo ' checked="checked"'; } ?> />
  179.         <label for="save-stuff">&nbsp; Save Name and Email?</label>
  180.     </li>  
  181.    
  182.     <li class="inline">
  183.         <input type="hidden" name="submitted" id="submitted" value="true" />
  184.         <button type="submit">Send</button>
  185.     </li>
  186. </ol>
  187. </form>
  188.        
  189.     <?php endwhile; ?>
  190. <?php endif; ?>
  191. <?php } ?>
  192. </div><!-- #left-content -->
  193.  
  194.     <div id="right"></div><!-- #right-content -->
  195.     </div><!-- #container -->
  196.  
  197. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement