Created
July 16, 2014 02:33
-
-
Save bign8/a167e7b881e5570732ab to your computer and use it in GitHub Desktop.
Mailer.php
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 session_start(); $_SESSION['hash'] = uniqid(); ?> | |
<!-- ... --> | |
<form method="post" action="/mail.php"> | |
<input type="hidden" name="hash" value="<?php echo $_SESSION['hash']; ?>" /> | |
<!-- ... --> |
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 | |
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