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.

Dimitris Tsioumas
1,649 Pointsheader function not working
Hello,
I would like some help with the following problem:
No matter what I do, after clicking the "Send" button, I am not being redirected to "contact-thanks.php"

Dimitris Tsioumas
1,649 Points <?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: contact-thanks.php");
?>
Thanks!

Dimitris Tsioumas
1,649 Points <?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: contact-thanks.php");
?>
Thanks!
5 Answers

Jason Anello
Courses Plus Student 94,592 PointsIs that code at the top of your file? Do you have any blank lines before the opening <?php
?

Dimitris Tsioumas
1,649 Pointsyes it is,no I have no blank lines

Curtis Schrum
10,174 PointsTry putting the server url in. Like below without my brackets
header("Location: http://[INSERT SERVER URL HERE]/contact-thanks.php");

Dimitris Tsioumas
1,649 Pointsunfortunatelly the problem still persists, I have even tried ' ' instead of " " as found on W3School

Jason Anello
Courses Plus Student 94,592 PointsOk, let's verify a few things.
You do have contact-thanks.php created and in the same folder?
Is the action attribute on your contact form going to "contact-process.php"?
And is the code you posted above inside "contact-process.php"?

Dimitris Tsioumas
1,649 PointsI quit everything, slept for a while, and now that I just tried it again it worked :P I would like to thank everybody for their help! ;)
Jason Anello
Courses Plus Student 94,592 PointsJason Anello
Courses Plus Student 94,592 PointsPost your php code so somebody can take a look.