<?php
	$SpamError = False;
	$SpamErrorMessage = "<p><b><font color=\"red\">Malicious code content detected.</font><br>Your IP Number of ".getenv("REMOTE_ADDR")." has been logged.</b></p>";
	$MissingInput = False;
	$MissingInputMessage = "<p><b><font color=\"red\">You must complete all items marked with a *</font></b></p>";
	$InvalidEmail = False;
	$InvalidEmailMessage = "<p><b><font color=\"red\">The email address you have entered appears to be incorrectly formatted.</font><b></p>";

	$MailAttempt = False;
	$MailResult = False;

if (isset($_POST["op"]) && ($_POST["op"]=="send")) { 
/******** START OF CONFIG SECTION *******/
	$sendto  = "allan.young@devsource.co.uk";
	$subject = "Website Contact Enquiry";
// Select if you want to check form for standard spam text
	$SpamCheck = "Y"; // Y or N
	$SpamReplaceText = "*content removed*";
/******** END OF CONFIG SECTION *******/

	$name = $_POST['name']; 
	$email = $_POST['email']; 
	$company = $_POST['company']; 
	$telephone = $_POST['telephone']; 
	$message = $_POST['enquiry']; 
	$headers = "From: $email\n";
	$headers . "MIME-Version: 1.0\n"
		   . "Content-Transfer-Encoding: 7bit\n"
		   . "Content-type: text/html;  charset = \"iso-8859-1\";\n\n";

	if ($SpamCheck == "Y") {		   
// Check for Website URL's in the form input boxes as if we block website URLs from the form,
// then this will stop the spammers wastignt ime sending emails
		if (preg_match("/http/i", "$name")) {$SpamError = True;} 
		if (preg_match("/http/i", "$email")) {$SpamError = True;} 
		if (preg_match("/http/i", "$message")) {$SpamError = True;} 

// Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer 
		$pattern = '/(;|\||`|>|<|&|^|"|'."\n|\r|'".'|{|}|[|]|\)|\()/i'; // build the pattern match string 
                            
		$name = preg_replace($pattern, "", $name); 
		$email = preg_replace($pattern, "", $email); 
		$message = preg_replace($pattern, "", $message); 
		$company = preg_replace($pattern, "", $company ); 
		$telephone = preg_replace($pattern, "", $telephone); 

// Check for the injected headers from the spammer attempt 
// This will replace the injection attempt text with the string you have set in the above config section
		$find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i"); 
		$email = preg_replace($find, "$SpamReplaceText", $email); 
		$name = preg_replace($find, "$SpamReplaceText", $name); 
		$message = preg_replace($find, "$SpamReplaceText", $message); 
		$company = preg_replace($find, "$SpamReplaceText", $company); 
		$telephone = preg_replace($find, "$SpamReplaceText", $telephone); 
  
// Check to see if the fields contain any content we want to ban
		if(stristr($name, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
		if(stristr($message, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
		if(stristr($company, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
		if(stristr($telephone, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
 
// Do a check on the send email and subject text
		if(stristr($sendto, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
		if(stristr($subject, $SpamReplaceText) !== FALSE) {$SpamError = True;} 
	}

// Build the email body text
	$emailcontent = "Name: $name\n"."Email: $email\n"."Company: $company\n"."Telephone: $telephone\n"."Message: $message"; 

// Check the email address entered matches the standard email address format
	if (!trim($name)) { $MissingInput = True; }

	elseif (!trim($message)) { $MissingInput = True; }

	elseif (!trim($email)) { $MissingInput = True; }

	elseif (!trim($company)) { $MissingInput = True; }

	elseif (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) { $InvalidEmail = True; }

// Sends out the email or will output the error message 
	else {
		$MailAttempt = True;
		$MailResult = mail($sendto, $subject, $emailcontent, $headers);
	} 
} 
else { 
	$name = ""; 
	$email = "";
	$company = ""; 
	$telephone = ""; 
	$message = "";
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DevSource - Get in touch</title>
<meta name="title" content=""/>
<meta name="abstract" content=""/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta name="author" content=""/>
<meta name="MSSmartTagsPreventParsing" content="TRUE"/>
<meta name="robots" content="index,follow"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta http-equiv="content-style-type" content="text/css"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="imagetoolbar" content="no"/>
<meta http-equiv="revisit-after" content="15 days"/>
<link href="./default.css" rel="stylesheet" type="text/css" />
</head>
<body id="getintouch">
<div id="wrapper">
	<div>
	<?php include './header.inc'; ?>
	<h1>get in touch</h1>
	<p class="address">
	<strong>DevSource</strong><br/>
	Technology House<br/>
	151 Silbury Boulevard<br/>
	Milton Keynes MK9 1LH<br/>
	<a href="http://maps.google.co.uk/maps?f=l&hl=en&q=Technology+House&near=MK9+1LH&ie=UTF8&z=17&ll=52.038831,-0.770652&spn=0.005728,0.013497&om=1&iwloc=A" target="_blank">Get directions and view map</a><br/>
	</p>

	<?php
		if ($SpamError) {
			echo $SpamErrorMessage;
		}
		
		elseif ($MailAttempt && MailResult) {
			echo "<p><b>Thank you for your interest, your enquiry has been sent and someone will get back to you shortly.</b></p>";
		}

		else {
			if ($MissingInput) {
				echo $MissingInputMessage;
			}

			elseif ($MailAttempt) {
				echo "<p><b><font color=\"red\">The email failed to send, please try again.  If this problem persists please send an email directly to".$sendto."</font></b></p>";
			}

			elseif ($InvalidEmail) {
				echo $InvalidEmailMessage;
			}
	
			else {
				echo "<p>If you would like to get in touch with us please fill out the form below and we will contact you as soon as we can.<br>Items marked with a * are required</p>";
			}

			echo "<form name=\"frm\" method=POST>";
			echo "<input name=\"op\" type=\"hidden\" value=\"send\">";
			echo "<label for=\"name\">Name<sup>*</sup></label><br/>";

			echo "<input name=\"name\" id=\"name\" type=\"text\" maxlength=\"100\" value=\"".$name."\" /><br/>";

			echo "<label for=\"email\">Email<sup>*</sup></label><br/>";

			echo "<input name=\"email\" id=\"email\" type=\"text\" maxlength=\"100\" value=\"".$email."\" /><br/>";

			echo "<label for=\"company\">Company<sup>*</sup></label><br/>";

			echo "<input name=\"company\" id=\"company\" type=\"text\" maxlength=\"100\" value=\"".$company."\" /><br/>";

			echo "<label for=\"telephone\">Telephone</label><br/>";

			echo "<input name=\"telephone\" id=\"telephone\" type=\"text\" maxlength=\"30\" value=\"".$telephone."\" /><br/>";

			echo "<label for=\"enquiry\">Enquiry<sup>*</sup></label><br/>";

			echo "<textarea name=\"enquiry\" id=\"enquiry\" cols=\"52\" rows=\"7\" >".$message."</textarea><br/>";

	                echo "<input type=\"image\" src=\"./Images/button.gif\" name=\"Submit\" value=\"Submit\" alt=\"send\" class=\"button\"/>";
			echo "</form>";

		} ?>
	</div>
</div>
<?php include './footer.inc'; ?>
</body>
</html>