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

PHP Build a Simple PHP Application Adding a Contact Form Redirecting After a Form Submission

My PHP header refuses to redirect. Help!


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

// TODO: Send Email



No echo statements beforehand.. I have looked in the contact page and the index page as well as the header and footers. I'm at a complete loss here.

3 Answers

Hi Adam,

You have a typo in your file name "coctact-thanks.php"

I actually progressed a little further and found that the redirect is replaced and it works fine now. I did fix that typo and still couldn't get it to open 'contact-thanks.php' though.

so weird.

The conditional is a much more streamlined solution anyways I suppose.

Yes, later on you end up doing everything within "contact.php"

I wonder if you had a blank line or any whitespace before your opening php script. That also prevents the redirect from happening.

If I remember correctly, the instructor used a conditional statement to redirect the header. Checking if it had a method of post or not (or get). I would rewatch the video.

Also it could be because of "coctact" when it should say contact. header("Location: contact-thanks.php");

Hi Ricardo,

I believe he's at an earlier version before that.

Wow, I scoured so many pages removing echo statements in the includes and really just wracking my brain. Of course it was a typo. Thanks so much for the quick reply gentleman.