Advertisement
keihead

cf

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