Created
March 23, 2014 22:02
-
-
Save bmelton/9730578 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if($HTTP["request-method"] == "POST") { | |
//error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP | |
//If the form is submitted | |
if(isset($_POST['submitted'])) { | |
// require a name from user | |
if(trim($_POST['contactName']) === '') { | |
$nameError = 'Forgot your name!'; | |
$hasError = true; | |
} else { | |
$name = trim($_POST['contactName']); | |
} | |
// need valid email | |
if(trim($_POST['email']) === '') { | |
$emailError = 'Forgot to enter in your e-mail address.'; | |
$hasError = true; | |
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) { | |
$emailError = 'You entered an invalid email address.'; | |
$hasError = true; | |
} else { | |
$email = trim($_POST['email']); | |
} | |
// we need at least some content | |
if(trim($_POST['comments']) === '') { | |
$commentError = 'You forgot to enter a message!'; | |
$hasError = true; | |
} else { | |
if(function_exists('stripslashes')) { | |
$comments = stripslashes(trim($_POST['comments'])); | |
} else { | |
$comments = trim($_POST['comments']); | |
} | |
} | |
// we need phone number | |
if(trim($_POST['phone']) === '') { | |
$phoneError = 'You forgot to enter a phone number'; | |
$hasError = true; | |
} else { | |
if(function_exists('stripslashes')) { | |
$phone = stripslashes(trim($_POST['phone'])); | |
} else { | |
$phone = trim($_POST['phone']); | |
} | |
} | |
// upon no failure errors let's email now! | |
if(!isset($hasError)) { | |
$emailTo = 'gzuiderweg@gmail.com'; | |
$subject = 'Submitted message from '.$name; | |
$sendCopy = trim($_POST['sendCopy']); | |
$body = "Name: $name \n\nEmail: $email \n\Phone: $phone \n\nComments: $comments"; | |
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; | |
mail($emailTo, $subject, $body, $headers); | |
// set our boolean completion value to TRUE | |
$emailSent = true; | |
} | |
} | |
} else { | |
?><!DOCTYPE html> | |
<html> | |
<head> | |
<!-- all your HTML goes here --> | |
</body> | |
</html> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment