Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Chase Lee
Chase Lee
29,275 Points

Redirecting After a Form Submission


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:

    $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:

    $page_title = "Contact Mike";
    $section = "contact";
    include("inc/header.php"); ?>

    <div class="section_page">

        <div class="wrapper">


            <p>Thanks for the email. I&rsquo;ll be in touch shortly.</p>



    <?php include("inc/footer.php"); ?>

And here is a link to my layout.


2 Answers

Chase Lee
Chase Lee
29,275 Points

Figured it out. Had to take out the echo command.

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Yep. Once anything gets echo'd out or displayed to the screen, it is too late to set headers. Glad you got it working!

Hi I have a question about redirecting contact forms.

This 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?