Hi can anyone advise me on where I am going wrong! when I submit my form I get this message >
Warning: Cannot modify header information - headers already sent by (output started at /home/hoteldirect/public_html/mailer.php:1) in /home/hoteldirect/public_html/mailer.php on line 35
Line 35 is on my php form is >
/* Redirect visitor to the thank you page */
header(‘Location: thankyou.html’);
exit();
This is my php form in full >
<?php $to = "[email protected]"; /* Check all form inputs using check_input function */ $name = check_input($_POST['name'], "Enter your name"); $email = check_input($_POST['email']); $tel = check_input($_POST['tel'], "Enter your Telephone number"); $business = check_input($_POST['business'], "Enter your business name"); $captcha = check_input($_POST['captcha']); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("Email address not valid"); } if (!preg_match("/5/", $captcha)) { show_error("Oops! please enter the correct maths number"); } /* Let's prepare the message for the e-mail */ $message = " Name: $name Email: $email Telephone number: $tel Business: $business "; /* Send the message using mail() function */ mail($to,$subject,$message,$headers," -f [email protected]"); /* Redirect visitor to the thank you page */ header('Location: thankyou.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?>Please correct the following error:
<?php echo $myError; ?>Hit the back button and try again
<?php
exit();
}
?>
And this is a suggested set up from my server >
To get this form to work with our hosting properly you will need to set the “From” address in the code as below:
Where the code says: mail($to,$subject,$message,$headers);
You need to add the from address in this format:
mail($to,$subject,$message,$headers,"-f [email protected]");
I am a newbie and the form works fine apart from redirecting to a custom thank you page, I have tried everything but still does not work! any advice to solve this problem would be greatly appreciated
Thanks
Paul