tmallen Posted May 12, 2008 Share Posted May 12, 2008 My server's been throwing errors when I send a late header after using the mail() function to send myself user feedback from a site contact form. I know that all headers have to be sent right away, so what's the way to redirect the user after the form's been sent successfully? Right now, I have the form and its script in the same file, so form action="contact.php" which is the form's page. <?php if (empty($errors)) { // $to, $subject, $message, and $headers are all assigned values // Send the email mail($to, $subject, $message, $headers); // This line seems to be generating header() errors. // Check header() functionality to correct header("Location: ./thanks.php"); } else { echo "\n<p>There were errors sending your message:</p>\n<ul>\n"; foreach ($errors as $message) { echo "<li>$message</li>\n"; } echo "</ul>\n"; } ?> How do I send users to thanks.php after mail() works? Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/ Share on other sites More sharing options...
DeanWhitehouse Posted May 12, 2008 Share Posted May 12, 2008 put ob_start(); at the begging of the page Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538722 Share on other sites More sharing options...
tmallen Posted May 12, 2008 Author Share Posted May 12, 2008 Hate to go on something blindly. I've read over the docs for ob_start(), and it's not entirely clear to me what this function will do when called at the start of the page, and why I should use it. Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538757 Share on other sites More sharing options...
phpretard Posted May 12, 2008 Share Posted May 12, 2008 Are you getting a caN'T REDIRECT BLAH BLAH BLAH? Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538771 Share on other sites More sharing options...
mars_rahul Posted May 12, 2008 Share Posted May 12, 2008 Yes, i agree with u. The function ob_start(). i have also used it so that while error occuring while generating output before header sends any information to other page. Please suggest me if u people have any suggestion regarding it. Me too also waiting Thanks Rahul - IT Professional. Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538831 Share on other sites More sharing options...
haku Posted May 12, 2008 Share Posted May 12, 2008 Is there more code above the code you have posted? I'm guessing there is. If there is, please post it, your error is coming from there. Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538833 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2008 Share Posted May 12, 2008 Just output the thank-you content on that page. Why waste the time it takes to redirect the browser to another page. Link to comment https://forums.phpfreaks.com/topic/105209-how-should-i-execute-this-redirect/#findComment-538910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.