Ahh... That would make more sense.. Doh!
Its PHP, he're is the specific function, you'll notice i'm trying foamcows logic, which i think should work as i did notice MIME: Version: in the attmepted attack, but anything to strengthen it further would be great, and always usefull in future:
//submit the contact us form
function contact_us(){
if(!isset($_POST['has_submit']) || $_POST['has_submit'] == 'False'){ //they havn't submit the form so display it
contact_us_form();
}else{ //they have submit the form
if(empty($_POST['name']) || empty($_POST['telephone']) || empty($_POST['email']) || empty($_POST['address']) || empty($_POST['enquiry'])){ //the fields are empty
echo "Please fill out the following fields first:<br /><ul>";
if (empty($_POST['name']))
echo "<li>Name</li>";
if (empty($_POST['telephone']))
echo "<li>Telephone</li>";
if (empty($_POST['email']))
echo "<li>E-Mail</li>";
if (empty($_POST['address']))
echo "<li>Address</li>";
if (empty($_POST['enquiry']))
echo "<li>Enquiry Details</li>";
echo "</ul>";
contact_us_form();
}else{ //everything is filled in
if (!check_email_address($_POST['email'])){
echo "Your email address in not valid...";
contact_us_form();
}else{ //everything is good, lets submit the enquiry
$name=$_POST['name'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$address=$_POST['address'];
$enquiry=$_POST['enquiry'];
$reciever="xxx@yyyy.co.uk";
$subject="New on-line enquiry";
//Rudimentary check for email injection hack
if (eregi("MIME-Version: ", $name.$telephone.$email.$address.$equiry.$reciever.$subject)) {
mail("xxxx@yyyy.co.uk", "xxx - Email injection attempt", "Attempted email injection on yyyy.co.uk");
die('Spammers not welcome!');
}else{
$url = (isset($HTTP_HOST)) ? "
: "
//if the server doesn't have it set, set the site root
$body="A new online enquiry has been submitted, details below:
Name: $name
Telephone: $telephone
Email: $email
Address:
$address
$enquiry";
$headers = 'From: xxx <xxx@yyy.co.uk>' . "\r\n" .'Reply-To: xxx@yyy.co.uk' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if (mail($reciever, $subject, $body, $headers)){
echo "Enquiry Successfully Sent...";
}else{
echo "Enquiry not sent, please try again...";
contact_us_form();
}
}
}
}
}
} //end of contact us