<?php

function CleanEmail($strEmail){

	/* 
	1) only use the first 128 characters
	this is the maximum length of an email address and if the string passed is longer it's probably a spam hijack
	*/
	
	$strReturn = substr($strEmail, 0, 128);
	
	/*
	2) remove carriage return line feed characters
	*/
	
	$strReturn = str_replace("\\r", "", $strReturn);
  	$strReturn = str_replace("\\n", "", $strReturn);

	 /*
	 3) Remove injected headers
	 */
	 
  	$arrHeaders = array("/bcc\:/i", "/Content\-Type\:/i", "/Mime\-Type\:/i", "/cc\:/i", "/to\:/i");
	
  	$strReturn = preg_replace($arrHeaders, "**bogus header removed**", $strReturn);

	// Return the clean string
	return $strReturn;

}

function IsValidEmail($strEmail){

	if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,6})$", $strEmail)){
		$blnResult = true;
	} else {
		$blnResult = false;
	}
	
	return $blnResult;
}

$strAction = $_POST["hidAction"];

if ($strAction == "send_email"){

	$iErrors = 0;
	$sErrors = "<strong>Sorry, your enquiry could not be sent for the following reason(s):</strong><br /><br />";
                                        
	$strEmail       = CleanEmail($_POST["txtEmail"]);
	$strName        = $_POST["txtName"];
	$strSubject     = $_POST["txtSubject"];
	$strComments     = $_POST["txtComments"];
		
	$strBody = "The following enquiry has been generated from the www.salads.com.au website ...\n\nName: ". $strName ."\nEmail: ". $strEmail ."\nSubject: ". $strSubject ."\nComments: ". $strComments;
	
	if(strlen($strName) == 0){
		$iErrors++;
		$sErrors .= $iErrors .") Please enter your name.<br />";
	}
	
	if(strlen($strEmail) == 0){
		$iErrors++;
		$sErrors .= $iErrors .") Please enter your email address.<br />";
	} else {
		if(!IsValidEmail($strEmail)){
			$iErrors++;
			$sErrors .= $iErrors .") ". $strEmail ." is not a valid email address. Please check and re-enter your email address.<br />";
		}
	}
	
	if($iErrors == 0){
	
		$strRecipient = "salads@salads.com.au";
		$strSubject = "Online Enquiry - ". $strSubject;
		$strHeaders = "From: ". $strEmail ."\r\n";
		
		$blnSuccess = mail($strRecipient, $strSubject, $strBody, $strHeaders);
		
	}
} 
?>
<!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" lang="en">
<head>
	<title>Queensland Salads &amp; Potato Products - Contact Us</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<meta http-equiv="Content-Language" content="en" />
	<meta name="robots" content="index, follow" />
	<meta name="robots" content="index, all" />
	<meta name="revisit-after" content="14 days" />
	<meta name="keywords" content="" />
	<meta name="description" content="Queensland Salads &amp; Potato Products - Contact Us)" />
	<link href="style_orange.css" rel="stylesheet" type="text/css" media="screen"  />
	<!--<link href="../../saladscomau.melbourneitwebsites.com/affiliate/templatecss/fresh/print.html" rel="stylesheet" media="print" type="text/css" />-->
	<script type="text/javascript" src="scripts/listmenuv.js"></script>
    <script type="text/javascript" src="scripts/general.js"></script>
    <script type="text/javascript">
	function Validate(){
	
		var intErrors = 0;
		var strErrors = "Sorry, your message could not be sent for the following reasons:\n\n";
		
		if(trim(document.frm.txtName.value) == ""){
			intErrors++;
			strErrors+= intErrors +") Please enter your name.\n";
		}
		
		if(trim(document.frm.txtEmail.value) == ""){
			intErrors++;
			strErrors+= intErrors +") Please enter your email address.\n";
		} else {
			if(!IsValidEmail(document.frm.txtEmail.value)){
				intErrors++;
				strErrors+= intErrors +") Please enter a valid email address.\n";
			}
		}
		
		if(0 == intErrors){
			return true;
		} else {
			alert(strErrors);
			return false;
		}
	}
	</script>

    <style type="text/css">
	<!--
	fieldset, legend, label { padding: 0; margin: 0; border: 0; }
	legend { display: none; }
	label { width: 10em; float: left; padding: 5px 25px 5px 0px; }
	label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
	em { color: red }
	-->
	</style>
</head>
<body>
<!-- wrap starts here -->
<div id="wrap-out">
	<!--header -->
	<div id="header"><a href="index.html"><img src="logo/logo.jpg" border="0" /></a></div>					
	<!--header ends-->					
	<!-- content-wrap starts -->
	<div id="content-wrap">		
		<div id="main">
			<?php
            if ($strAction == "send_email" && $iErrors == 0){
                echo('<p style="padding-left:0px;"><b>Email Sent</b><br />');
                echo('Thank you '. $strName .', your message has been sent and we will get back to you as soon as possible.</p>');
				echo('<hr style="height:1px; width:50%;" />');
            } else {
                if ($strAction == "send_email" && $iErrors > 0){
                    echo('<br /><div style="color:#FF0000;">'. $sErrors .'</div><br />');
                }
            }	
            ?>
            Please complete the following details:<br /><br />
            <form name="frm" id="frm" method="post" action="contact.php" onsubmit="return Validate();">
            <input type="hidden" name="hidAction" value="send_email" />
            <fieldset>
            <legend>Personal information</legend>
                <label for="fname">Name:<em>*</em></label> <input type="text" name="txtName" id="txtName" class="required" /><br style="clear: both;" />
                <label for="email">Email address:<em>*</em></label> <input type="text" name="txtEmail" id="txtEmail" class="required email" /><br style="clear: both;" />
            </fieldset>
            
            <fieldset>
            <legend>Comments</legend>
              <label for="email">Email subject:</label> <input type="text" name="txtSubject" id="txtSubject" /><br style="clear: both;" />
              <label for="comments">Your comments:</label><br /> <textarea cols="35" rows="5" name="txtComments" id="txtComments"></textarea><br style="clear: both;" />
            </fieldset>
            <input type="submit" name="submit" value="Submit" />
            </form>
            <!-- main ends -->	
        </div>	
		<!-- sidebar starts -->
		<div id="navbar">
			<ul id="primary-nav">
				<li><a href="index.html">Home</a></li>
				<li><a href="contact.php">Contact Us</a></li>
			</ul>
			<!-- sidebar ends -->		
		</div>
	<div class="clear"></div>
	<!-- content-wrap ends-->	
	</div>
	<!-- footer starts here -->	
	<div id="footer-wrap"><div id="footer-content">
	<p><a href="index.html">Home</a>&nbsp;|&nbsp;&nbsp;<a href="contact.php">Contact Us</a></p>
	</div></div>
	<!-- footer ends here -->
<div class="clear"></div>
<!-- wrap ends here -->
</div>
</body>
</html>