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 triallindseyfowler
4,526 PointsRedirecting
Hi,
I'm attempting to create a contact form on a HTML page. I've been using this tutorial to help me along and have come to a stop at this step. When I use header(Location: ...) the contact-process page doesn't load after 'Send' is clicked.
Any and all help is appreciated =]
3 Answers
Jason Anello
Courses Plus Student 94,610 Pointsheader
does not work if there is any output to the page before it. In this case you have included header.php before the header
redirect. Since header.php does echo output to the page it would cause the redirect not to work.
Not sure if this helps with your problem but without seeing your code I can only suggest that you make sure you don't have any output to the page before header(Location...
Guillermina Frind
1,046 PointsHi, I was following the tutorial, and can't seem to make it work either. I can't find any mistakes (I am a beginner though) and I can't find a difference with the code that's in the tutorial.
Here is the contact-process.php
<?php
include('includes/header.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");
?>
Here's the contact-thanks.php
<?php
$pageTitle = "Contact Mike"; $section = "contact"; include('includes/header.php');
?>
<div class="section page">
<div class="wrapper">
<h1>Contact us</h1>
<p> Thanks for the email! I’ll be in touch shortly.</p>
</div>
</div>
<?php include("includes/footer.php"); ?>
When I click send, so it submits the data to $_POST, it redirects to contact-process.php and shows it blank.
Can anybody spot the mistake?
Thank you!
Guillermina Frind
1,046 PointsThanks Jason Anello! That was very helpful
Jason Anello
Courses Plus Student 94,610 PointsYou're welcome.
Jeff Busch
19,287 PointsJeff Busch
19,287 PointsCan we see your code?