Skip to content

Instantly share code, notes, and snippets.

@mattbontrager
Created November 14, 2012 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbontrager/4074557 to your computer and use it in GitHub Desktop.
Save mattbontrager/4074557 to your computer and use it in GitHub Desktop.
A simple script to process emails sent via contact forms
<?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@goeshere.com';
$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