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 trialAdam Shockley
3,911 PointsMy PHP header refuses to redirect. Help!
<?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;
// TODO: Send Email
header('Location:coctact-thanks.php');
?>
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
Jason Anello
Courses Plus Student 94,610 PointsHi Adam,
You have a typo in your file name "coctact-thanks.php"
Ricardo Hill-Henry
38,442 PointsIf 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");
Jason Anello
Courses Plus Student 94,610 PointsHi Ricardo,
I believe he's at an earlier version before that.
Adam Shockley
3,911 PointsWow, 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.
Adam Shockley
3,911 PointsAdam Shockley
3,911 PointsI 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.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYes, 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.