Created
November 14, 2012 20:27
-
-
Save mattbontrager/4074557 to your computer and use it in GitHub Desktop.
A simple script to process emails sent via contact forms
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 | |
$name = (isset($_REQUEST['name']) && !empty($_REQUEST['name'])) ? $_REQUEST['name']: null; | |
$temp_email = (isset($_REQUEST['email']) && !empty($_REQUEST['email'])) ? $_REQUEST['email']: null; | |
/* server side email address validation */ | |
$email = (filter_var($temp_email, FILTER_VALIDATE_EMAIL)) ? $temp_email: null; | |
$subject = (isset($_REQUEST['subject']) && !empty($_REQUEST['subject'])) ? $_REQUEST['subject']: null; | |
$message = (isset($_REQUEST['message']) && !empty($_REQUEST['message'])) ? nl2br(trim($_REQUEST['message'])): null; | |
/* Additional email headers */ | |
$to = '[email protected]'; | |
$headers = 'From: ' . $name . '<' . $email . '>' . "\r\n" . | |
'X-Mailer: PHP/' . phpversion(); | |
if ($name && $email && $subject && $message) { | |
if (mail($to, $subject, $message, $headers)) { | |
echo 'yes'; | |
} | |
else { | |
echo "no"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment