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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Benjamin Wornell](https://secure.gravatar.com/avatar/ca5f4eb52585c9bd4113fc10b4b43159?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Benjamin Wornell
10,458 Pointsheader("Location: contact-thanks.php"); does not work
header("Location: contact-thanks.php"); does not work. It gets a NULL value.
The conditional works.
Code is as follows, which is as it appears in the video.
I've found a common reason for this is that actual output is sent prior to the header(). I don't see where that would be happening here
<?php if($_SERVER["REQUEST_METHOD"]=="POST"){ $name=$_POST["name"]; $email=$_POST["email"]; $message=$_POST["message"]; $email_body=""; $email_body=$email_body."Name: ".$name."\n"; $email_body=$email_body. "E-mail:".$email."\n"; $email_body=$email_body. "Message: ".$message."\n";
header("Location: contact-thanks.php");
exit;
}
2 Answers
![Adam Ridgley](https://uploads.teamtreehouse.com/production/profile-photos/1219942/micro_70508048_10220167490522905_7097376574093131776_n.jpg)
Adam Ridgley
12,255 PointsI've had an issue like this when I had some white space after a closing PHP tag. Your code works fine for me:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$email_body = "";
$email_body = $email_body."Name: ".$name."\n";
$email_body=$email_body. "E-mail:".$email."\n";
$email_body=$email_body. "Message: ".$message."\n";
header("Location: contact-thanks.php");
exit;
}
?>
![Benjamin Wornell](https://secure.gravatar.com/avatar/ca5f4eb52585c9bd4113fc10b4b43159?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Benjamin Wornell
10,458 PointsThis was close enough. The problem was a blank line at the top of the file. My opening <?php tag started on line 2. NoviceProblems.