Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Chase Lee
29,275 PointsRedirecting After a Form Submission
Hi,
I am doing "Redirecting After a Form Submission" in "Build a Simple PHP Application", and got to the part where Randy has us take the users to the "contact-thanks.php
". But it dosen't work for me.
Here is the code I have in contact-process.php
:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " . $message;
echo $email_body;
//TODO: Send Email
header("Location: contact-thanks.php");
?>
Here is contact-thanks.php
:
<?php
$page_title = "Contact Mike";
$section = "contact";
include("inc/header.php"); ?>
<div class="section_page">
<div class="wrapper">
<h1>Contact</h1>
<p>Thanks for the email. I’ll be in touch shortly.</p>
</div>
</div>
<?php include("inc/footer.php"); ?>
And here is a link to my layout.
Thanks.
2 Answers

Chase Lee
29,275 PointsFigured it out. Had to take out the echo command.

adrie silva
6,416 PointsThis question is for Randy,
If I'm placing my contact form in an iframe, or using an iframe, the function header () won't work, what do you suggest?
Thanks!
Randy Hoyt
Treehouse Guest TeacherRandy Hoyt
Treehouse Guest TeacherYep. Once anything gets echo'd out or displayed to the screen, it is too late to set headers. Glad you got it working!
adrie silva
6,416 Pointsadrie silva
6,416 PointsHi I have a question about redirecting contact forms.