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 trialDimitris 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,610 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,610 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,610 PointsJason Anello
Courses Plus Student 94,610 PointsPost your php code so somebody can take a look.