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-Z]{2,4}$", 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']);
- }
- }
- //If there is no error, send the email
- if(!isset($hasError)) {
- $emailTo = 'email@domain.com';
- $subject = $subject;
- $sendCopy = trim($_POST['sendCopy']);
- $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments: $comments";
- $headers = 'From: Your Name . <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
- 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>
- <?php if(isset($hasError) || isset($captchaError)) { ?>
- <h2 class="error">There was an error submitting the form.</h2>
- <?php } ?>
- <form action="<?php the_permalink(); ?>" 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="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 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><!-- #container -->
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement