Forum Moderators: coopster
I continue to get the "header already sent..." message and I have checked for whitespace, and html before php and all of the solutions that are suggestion on these boards. Still I am not getting it right. The email form works, but the redirect does not.
I am really new to this (in case you couldn't figure that out yourself) so thank you for any help you can offer.
<?
$name = $_POST['name'];
$email = $_POST['email'] ;
$phone = $_POST['phone'];
$message = $_POST['comments'] ;
mail( "kathy@example.com", "Information Request from Website",
"$message\nPhone Number $phone\n", "From: $name <$email>" );
header( 'Location: http://www.example.com/thankyou.html');
?>
[edited by: dreamcatcher at 8:11 pm (utc) on Oct. 17, 2007]
[edit reason] Use example.com, thanks. [/edit]
If this code is not the only thing on the page is it at the very top of the page, or half way down?
Welcome to webmaster world and the wonderful world of example.com (dont worry you are not the first to keep your url as it actually is in the code).
the php is included in the code for the entire contact page. in the middle. should I move the entire code for the form to the top? I wasnt sure if this would completely screw things up.
and i'm sorry, but i don't know what you mean about example.com
speak slowly, i'm new. :)
Once you have the first < of the DTD something has been sent to the browser, so you cant send headers, unless you want to get into buffering.
[edited by: PHP_Chimp at 9:13 pm (utc) on Oct. 17, 2007]
So you want to check if there is any content. You could just use -
if {$_POST) {
// your code in here
}
I assume that you are checking the $email filed to check that people are not putting me@spam.com, another@spam.com, another1@spam.com, etc. As otherwise your form will be spamming everyone as soon as the bots find it.
###BEGIN REDIRECT IF HEADER ALREADY SENT
function Redirect($url) {
if(headers_sent()) {
echo "<script type='text/javascript'>location.href='$url';</script>";
} else {
header("Location: $url");
}
}
//usage
//Redirect('somewhere.html');
###END REDIRECT IF HEADER SENT