<?php
if (!isset($_POST['submit']) || $_SERVER['REQUEST_METHOD']
!= "POST") {
exit("<p>You did not press the submit button; this page
should not be accessed directly.</p>");
} else {
$exploits =
"/(content-type|bcc:|cc:|document.cookie|onclick|onload|java
script|alert)/i";
$profanity =
"/(RUDE WORDS HERE)/i";
$spamwords =
"/(SPAMWORDS HERE)
/i";
$bots =
"/(Indy|Blaiz|Java|libwww-perl|Python|OutfoxBot|User-Agent|P
ycURL|AlphaServer)/i";
if (preg_match($bots, $_SERVER['HTTP_USER_AGENT'])) {
exit("<p>Known spam bots are not allowed.</p>");
}
foreach ($_POST as $key => $value) {
$value = trim($value);
if (empty($value)) {
exit("<p>Empty fields are not allowed. Please go
back and fill in the form.</p>");
} elseif (preg_match($exploits, $value)) {
exit("<p>Exploits/malicious scripting attributes
aren't allowed.</p>");
} elseif (preg_match($profanity, $value) ||
preg_match($spamwords, $value)) {
exit("<p>That kind of language is not allowed
through our form.</p>");
}
$_POST[$key] = stripslashes(strip_tags($value));
}
if
(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*
(.[a-z]{2,6})$",strtolower($_POST['email']))) {
exit("<p>That e-mail address is not valid, please
use another.</p>");
}
$recipient = "me";
$subject = "Contact From mydomain";
$message = "You've received an enquiry from: \n";
$message .= "Name: {$_POST['name']} \n";
$message .= "E-mail: {$_POST['email']} \n";
$message .= "Telephone: {$_POST['telephone']} \n";
$message .= "Country: {$_POST['country']} \n";
$message .= "Enquiry: {$_POST['comments']} \n";
$headers = "From: <$recipient> \n";
$headers .= "Reply-To: <{$_POST['email']}>";
if (mail($recipient,$subject,$message,$headers)) {
header ("Location: thankyou.php");
} else {
header ("Location: opps.php");
}
}