Hi,
I am trying to put a form on my client's website.
http://www.sleightfarm.com It asks for name, address, city, etc. I got everything to work nicely except I am now getting an error message when we are hitting the "Send" button instead of the form re-directing to our thank you page. (Not to mention our error page is not showing up either.)
Error Message I am getting when hitting send---> "Warning: Cannot modify header information - headers already sent by (output started at /home/content/30/9210630/html/send_mail.php:89) in /home/content/30/9210630/html/send_mail.php on line 95"
I have my form on my index.html page, a thank_you.html page, a error_message.html page and a send_mail.php. I've gone into the PHP file to line 95 and this seems to be the error spot
PHP Code:
header("Location:$thankyou_page");
It's one of the last lines of code in the PHP file. Line 89 has code about echo
PHP Code:
echo "Sent to $sEmailAddress";
I've been reading up on this and people mention something about deleting white space or the header information needing to come before something? I am completely new when it comes to this stuff, so I'm sort of lost on what to change or move around. Can anyone point me in the right direction or tell me what I need to change around in my send_mail.php file? Thank you in advance for any help. These forums have been lifesavers for me!!!
PHP Code:
<?php
/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$aEmailTo = array(
"screaminglizzard@gmail.com",
"liz@wisewebsitecreations.com"
);
/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "index.html";
$error_page = "error_message.html";
$thankyou_page = "thank_you.html";
/* Try not to change below this line if possible
-------------------------------------------------------------------- */
/* ERROR CHECKING AND FORM VALIDATION
-------------------------------------------------------------------- */
if ($_POST && $_POST['submit_form']) {
// Clean Data and Check for Errors.
$aErrors = array();
foreach($_POST as $sField => $mValue){
$aClean[$sField] = filter_input(INPUT_POST,$sField,FILTER_SANITIZE_STRING);
if(empty($aClean[$sField]) || trim($aClean[$sField]) == '') $aErrors[$sField] = true; // If empty or blank add an error.
}
if(isInjected($aClean['email'])) $aErrors['email'] = true;
// Count the errors and if more than 0 show error page.
if(count($aErrors)>0){
header( "Location: $error_page" );
exit();
}
/* OK No errors? Great... SEND THE FORM.
-------------------------------------------------------------------- */
else {
// Construct the email message.
$sHTML = '<strong>'.$aClean['firstname'].'</strong> sent you the following message,<br />';
$sHTML .= '<strong>Firstname: </strong>'.$aClean['firstname'].'<br />';
$sHTML .= '<strong>Lastname: </strong>'.$aClean['lastname'].'<br />';
$sHTML .= '<strong>Email: </strong>'.$aClean['email'].'<br />';
$sHTML .= '<strong>Phone: </strong>'.$aClean['phone'].'<br />';
$sHTML .= '<strong>Address: </strong>'.$aClean['address'].'<br />';
$sHTML .= '<strong>City: </strong>'.$aClean['city'].'<br />';
$sHTML .= '<strong>State: </strong>'.$aClean['state'].'<br />';
$sHTML .= '<strong>Zip: </strong>'.$aClean['zip'].'<br />';
$sHTML .= '<strong>Best Way to Contact: </strong>'.$aClean['contact'].'<br />';
$sHTML .= '<strong>How Did You Hear About Us?: </strong>'.$aClean['referral'];
// For every email address send the message.
foreach($aEmailTo as $iIndex => $sEmailAddress){
echo "Sent to $sEmailAddress";
$sHeaders = 'MIME-Version: 1.0' . "\r\n";
$sHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$sHeaders .= 'From: '.$aClean['firstname'].' <'.$aClean['email'].'>'."\r\n";
mail("$sEmailAddress","Feedback Form Results",$sHTML,$sHeaders);
}
header("Location:$thankyou_page");
exit();
}
}else{ // If they didn't hit submit send them back to the feedback form.
header( "Location: $feedback_page" );
exit();
}
?>
~Liz