Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Contact
- */
- ?>
- <?php
- //If the form is submitted
- if(isset($_POST['submitted'])) {
- //Check to see if the honeypot captcha field was filled in
- if(trim($_POST['checking']) !== '') {
- $captchaError = true;
- } else {
- //Check to make sure that the name field is not empty
- if(trim($_POST['contactName']) === '') {
- $nameError = 'You forgot to enter your name.';
- $hasError = true;
- } else if(strlen($_POST['contactName']) < 3) {
- $nameError = 'The name must be at least 3 characters long.';
- $hasError = true;
- } else {
- $name = trim($_POST['contactName']);
- }
- //Check to make sure sure that a valid email address is submitted
- if(trim($_POST['email']) === '') {
- $emailError = 'You forgot to enter your email address.';
- $hasError = true;
- } else if (!eregi("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", trim($_POST['email']))) {
- $emailError = 'You entered an invalid email address.';
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- //Check to make sure a subject was entered
- if(trim($_POST['subject']) === '') {
- $subjectError = 'You forgot to enter a subject.';
- $hasError = true;
- } else if(strlen($_POST['subject']) < 3) {
- $subjectError = 'The subject must be at least 3 characters long.';
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $subject = stripslashes(trim($_POST['subject']));
- } else {
- $subject = trim($_POST['subject']);
- }
- }
- //Check to make sure comments were entered
- if(trim($_POST['comments']) === '') {
- $commentError = 'You forgot to enter your comments.';
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $comments = stripslashes(trim($_POST['comments']));
- } else {
- $comments = trim($_POST['comments']);
- }
- }
- // SAVE INFO AS COOKIE, if user wants name and email saved
- $save = $_POST['save-stuff'];
- if ($save == true) {
- setcookie("name", $_POST['name'], time()+60*60*24*365);
- setcookie("email", $_POST['email'], time()+60*60*24*365);
- }
- //If there is no error, send the email
- if(!isset($hasError)) {
- $emailTo = 'keysarrr@gmail.com';
- $subject = $subject;
- $sendCopy = trim($_POST['sendCopy']);
- $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
- $body = '<html><body>';
- $body .= '<div align="center" style="width: 600px; color: #000; margin: 0 auto; padding: 20px; ">';
- $body .= '<img src="http://keihead.com/test/images/ks_email_header.png" />';
- $body .= '<h1 style="color: #000;">Contact Form</h1>';
- $body .= '<ul style="list-style: none; text-align: left;">
- <li><strong>Name:</strong> '.$name.'</li>
- <li><strong>Email:</strong> <em style="color: #FFF;">'.$email.'</em></li>
- <li style="border-bottom: 2px solid #FF0000;"><strong>Subject:</strong> '.$subject.'</li>
- <li>'.$comments.'</li>
- </ul>';
- $body .= '</div>';
- $body .= "</body></html>";
- mail($emailTo, $subject, $body, $headers);
- $headers = "From: Keisa L. <noreply@keihead.com>\r\n";
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
- $body = '<html><body>';
- $body .= '<div align="center" style="width: 600px; color: #000; margin: 0 auto; padding: 20px; ">';
- $body .= '<img src="http://keihead.com/test/images/ks_email_header.png" />';
- $body .= '<h1 style="color: #000; font-style: italic;">Thanks for contacting us!</br> We'll get back to you as soon as possible.</h1>';
- $body .= "Here is a copy of the email you recently sent us:";
- $body .= '<ul style="list-style: none; text-align: left;">
- <li><strong>Name:</strong> '.$name.'</li>
- <li><strong>Email:</strong> <em style="color: #FFF;">'.$email.'</em></li>
- <li style="border-bottom: 2px solid #FF0000;"><strong>Subject:</strong> '.$subject.'</li>
- <li>'.$comments.'</li>
- </ul>';
- $body .= '</div>';
- $body .= "</body></html>";
- mail($email, $subject, $body, $headers);
- $emailSent = true;
- }
- }
- } ?>
- <?php get_header('header2'); ?>
- <div id="container" class="clearfix">
- <div class="page-title">
- <h1 class="title">
- <span class="ico-music left FF0000"></span>
- <?php wp_title('');?>
- </h1>
- <span class="diag-title"></span>
- </div>
- <div id="left-content">
- <?php if(isset($emailSent) && $emailSent == true) { ?>
- <div class="thanks">
- <h1>Thanks <?=$name;?>,</h1>
- <p>Your email was successfully sent.</br> Please allow up to 24 hours for a response.</p>
- </div>
- <?php } else { ?>
- <?php if (have_posts()) : ?>
- <?php while (have_posts()) : the_post(); ?>
- <form action="" id="contactForm" method="post">
- <ol class="forms">
- <li>
- <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>" class="requiredField" placeholder="Name" />
- </br>
- <?php if($nameError != '') { ?>
- <span class="error"><?=$nameError;?></span>
- <?php } ?>
- </li>
- <li>
- <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="requiredField email" placeholder="Email" />
- </br>
- <?php if($emailError != '') { ?>
- <span class="error"><?=$emailError;?></span>
- <?php } ?>
- </li>
- <li>
- <input type="text" name="subject" id="subject" value="<?php if(isset($_POST['subject'])) echo $_POST['subject'];?>" class="requiredField subject" placeholder="Subject" />
- <br/>
- <?php if($subjectError != '') { ?>
- <span class="error"><?=$subjectError;?></span>
- <?php } ?>
- </li>
- <li class="textarea">
- <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>
- </br>
- <?php if($commentError != '') { ?>
- <span class="error"><?=$commentError;?></span>
- <?php } ?>
- </li>
- <li class="inline">
- <input type="checkbox" name="save-stuff" value="yes"<?php if(isset($_POST['save-stuff']) && $_POST['save-stuff'] == "yes") { echo ' checked="checked"'; } ?> />
- <label for="save-stuff"> Save Name and Email?</label>
- </li>
- <li class="inline">
- <input type="hidden" name="submitted" id="submitted" value="true" />
- <button type="submit">Send</button>
- </li>
- </ol>
- </form>
- <?php endwhile; ?>
- <?php endif; ?>
- <?php } ?>
- </div><!-- #left-content -->
- <div id="right"></div><!-- #right-content -->
- </div><!-- #container -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement