Last active
April 8, 2018 23:05
-
-
Save haydencarlson/41738c8045f3355f8b7e50a00a9ce9b7 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(isset($_POST['email'])) { | |
$message = $_POST['messages']; | |
$first_name = $_POST['name']; | |
$last_name = $_POST['lastname']; | |
$email = $_POST['email']; | |
$subject = $first_name . " " . $last_name . " is trying to contact you."; | |
function died($error) { | |
echo json_encode(array( | |
'result' => false, | |
'message' => $error, | |
'style' => 'formError' | |
)); | |
die(); | |
} | |
if (empty($_POST['name'])) { | |
died('Please enter your first name'); | |
} | |
if (empty($_POST['lastname'])) { | |
died('Please enter your last name'); | |
} | |
if (empty($_POST['messages'])) { | |
died('Please include a message'); | |
} | |
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; | |
if(!preg_match($email_exp,$email)) { | |
died('The Email Address you entered does not appear to be valid.'); | |
} | |
$email_message = "Form details below.\n\n"; | |
function clean_string($string) { | |
$bad = array("content-type","bcc:","to:","cc:","href"); | |
return str_replace($bad,"",$string); | |
} | |
$email_message .= "First Name: ".clean_string($first_name)."\n"; | |
$email_message .= "Last Name: ".clean_string($last_name)."\n"; | |
$email_message .= "Email: ".clean_string($email)."\n"; | |
$email_message .= "Message: ".clean_string($message)."\n"; | |
mail('{email you want to receive emails}', "$subject", $email_message, "From:" . 'sender@cpahub.us'); | |
echo json_encode(array( | |
'result' => true, | |
'message' => 'Thank you. We will respond to you as soon as possible.', | |
'style' => 'formSuccess' | |
)); | |
die(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment