Ugly Code

Good day, i recently got put incharge of a website for a friend. The contact forms on quote and repair both hang and try redirect the user after submitting the form. the re submit times out. Could you take a look at the code and see where this is being done, a simple echo “message sent” would be fine. Not sure where the original coder put this redirect command. http://www.pool-companies.co.za/contact/free-quote.php, please see the php below

[php]<?

if($_POST[‘task’] == ‘Submit’){

//proccess form
$to1 = '[email protected]';


	//if($_SESSION['validSession'] == 1 || $_SESSION['validSession'] == true){
	  $subject = "All Pools - Request a Quote";
	//}else{
	//  $subject = "Water Boys - Request a Quote - AUTOMATED [SPAM]";
	//}

  if (strtoupper(substr(PHP_OS,0,3)=='WIN')) { 
	$eol="\r\n"; 
  } elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) { 
	$eol="\r"; 
  } else { 
	$eol="\n"; 
  }
  
$body='<html><head><style>body{font-family:verdana,arial,tahoma;font-size:12px;}</style></head><body>'.chr(13);
$body.='<table width="480" cellpadding="2" cellspacing="0" border="0">'.chr(13); 
$body.='  <tr>'.chr(13); 
$body.='    <td valign="top">Date:</td><td valign="top">'.date('Y-m-j H:i:s').'</td>'.chr(13); 
$body.='  </tr>'.chr(13);

foreach($_POST as $key_name => $key_value) {

	if($key_value!='' && $key_name!='task' && $key_name!='x' && $key_name!='y'){
		$body.='<tr><td>'.str_replace('chb','',str_replace('chk','',str_replace('rbl','',str_replace('txt','',$key_name)))) . ':&nbsp;</td><td>' . $key_value .'</td></tr>';
	}

}

$body.='</table>'.chr(13); 
$body.='</body></html>'.chr(13); 

$headers = 'From: All Pools <[email protected]>'.$eol.
		   'Reply-To: All Pools <[email protected]>'.$eol.				   
		   'MIME-Version: 1.0'.$eol.
		   'Content-type: text/html; charset=iso-8859-1';

		$ok= mail($to1, $subject, $body, $headers);
		$ok= mail($to2, $subject, $body, $headers);
		$ok= mail($to3, $subject, $body, $headers);
		//$ok= mail($to4, $subject, $body, $headers);
		//$ok= mail($to5, $subject, $body, $headers);
		if ($ok){
		$mess="been sent";
		}else{
		$mess="not been sent";
		}
		
		
		
	 // Write request to html file
		$FileName = date('Y_m_j_H_i_s').".html";
		$FileHandle = fopen("../requests/".$FileName, 'w') or die("can't open file");
		fwrite($FileHandle, $body);
		fclose($FileHandle);

		Header("Location: /contact/");

}else{

		Header("Location: /contact/?err=not+submitted");

}

?>[/php]

And, it rightly should hang up. You did not give the script anywhere to go to. The following:

Header(“Location: /contact/”);
}else{
Header(“Location: /contact/?err=not+submitted”);

Goes notwhere

To REDIRECT to another page, you need to tell the header where it is…
Something like: header(“location: /contact/ErrorDisplay.php”);
NOTE: this sample has /contact/ which means to go to a subfolder under where the current page is.
(If you are currently at ROOT/, then the above would go to ROOT/contact/ErrorDisplay.php…

Hope that helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service