<?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 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 = 'me@somedomain.com';
$subject = 'Contact Form Submission from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: My Site ‘ . « \r\n » . ‘Reply-To: ‘ . $email;
mail($emailTo, $subject, $body, $headers);
if($sendCopy == true) {
$subject = ‘You emailed Your Name’;
$headers = ‘From: Your Name ‘;
mail($email, $subject, $body, $headers);
}
$emailSent = true;
}
}
} ?>
<script type="text/javascript" src="/scripts/contact-form.js »>
Thanks,
Your email was successfully sent. I will be in touch soon.
There was an error submitting the form.
<form action=" » id= »contactForm » method= »post »>
- Name
<input type="text" name="contactName" id="contactName" value=" » class= »requiredField » /> - Email
<input type="text" name="email" id="email" value=" » class= »requiredField email » /> - Comments
- <input type="checkbox" name="sendCopy" id="sendCopy" value="true" />Send a copy of this email to yourself
- If you want to submit this form, do not enter anything in this field<input type="text" name="checking" id="checking" class="screenReader" value=" » />