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 {
- $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(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'];
- 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: Your 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>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);
- if($sendCopy == true) {
- $headers = 'From: Your Name <noreply@somedomain.com>';
- $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";
- mail($email, $subject, $body, $headers);
- }
- $emailSent = true;
- }
- }
- } ?>
- <?php get_header('header2'); ?>
- <div id="container" class="clearfix">
- <div id="left-content">
- <?php if(isset($emailSent) && $emailSent == true) { ?>
- <div class="thanks">
- <h1>Thanks, <?=$name;?></h1>
- <p>Your email was successfully sent. I will be in touch soon.</p>
- </div>
- <?php } else { ?>
- <?php if (have_posts()) : ?>
- <?php while (have_posts()) : the_post(); ?>
- <h1><?php the_title(); ?></h1>
- <form action="" id="contactForm" method="post">
- <ol class="forms">
- <li>
- <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" 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="true"<?php if(isset($_POST['save']) && $_POST['save'] == true) echo ' checked="checked"'; ?> />
- <label for="save-stuff"> Save Name and Email?</label>
- </li>
- <li class="inline">
- <input type="checkbox" name="sendCopy" id="sendCopy" value="true"<?php if(isset($_POST['sendCopy']) && $_POST['sendCopy'] == true) echo ' checked="checked"'; ?> />
- <label for="sendCopy">Send a copy of this email to yourself</label>
- </li>
- <li>
- <?php
- session_start();
- include("captcha.php");
- $_SESSION['captcha'] = captcha( array(
- 'min_length' => 5,
- 'max_length' => 5,
- 'png_backgrounds' => array('default.png'),
- 'fonts' => array('times_new_yorker.ttf'),
- 'characters' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
- 'min_font_size' => 24,
- 'max_font_size' => 30,
- 'color' => '#000',
- 'angle_min' => 0,
- 'angle_max' => 15,
- 'shadow' => true,
- 'shadow_color' => '#CCC',
- 'shadow_offset_x' => -2,
- 'shadow_offset_y' => 2
- ));
- ?>
- </li>
- <li class="buttons">
- <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