Skip to content

Instantly share code, notes, and snippets.

@bign8
Created July 16, 2014 02:33
Show Gist options
  • Save bign8/a167e7b881e5570732ab to your computer and use it in GitHub Desktop.
Save bign8/a167e7b881e5570732ab to your computer and use it in GitHub Desktop.
Mailer.php
<?php session_start(); $_SESSION['hash'] = uniqid(); ?>
<!-- ... -->
<form method="post" action="/mail.php">
<input type="hidden" name="hash" value="<?php echo $_SESSION['hash']; ?>" />
<!-- ... -->
<?php
session_start();
if ($_POST['hash'] != $_SESSION['hash']) die(header('Location: /'));
$subject = "Contact: ";
$subject .= isset($_POST['subject']) ? $_POST['subject'] : 'No Subject';
$body = "The following was received:\n\n";
$body .= "Name: " . (isset($_POST['name']) ? $_POST['name'] : 'No Name') . "\n";
$body .= "Email: " . (isset($_POST['email']) ? $_POST['email'] : 'No Email') . "\n";
$body .= "Subject: " . (isset($_POST['subject']) ? $_POST['subject'] : 'No Subject') . "\n";
$body .= "Message: " . (isset($_POST['message']) ? $_POST['message'] : 'No Message') . "\n\n\n";
$body .= "Debug Data: " . print_r($_SERVER, true);
$test = mail("your@address.com", $subject, $body);
echo '<meta http-equiv="refresh" content="2; url=/" />';
echo $test ? 'Message sent!' : 'Message error!';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment