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.

PHP Build a Simple PHP Application Adding a Contact Form Checking the Request Method

Kim Gee
Kim Gee
3,841 Points

can't get the contact-thankyou.php page to show up after clicking the button. I am working on a server.

This is my code

<?php
if($_SERVER[“REQUEST_METHOD”] == "POST"){
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$email_body = "";
$email_body =$email_body .  "Name: ".$name . "<br>";
$email_body =$email_body. "Email: ".$email . "<br>";
$email_body=$email_body."Message: ".$message;

//todo- send email

header("Location: contact-thankyou.php");
exit; 
}
?>
<form method="post" action="contact.php">
Colin Marshall
Colin Marshall
32,861 Points

I fixed your code so it displays properly on the forum. Please read the Markdown Cheatsheet for instructions on how to post your code on the forum. You can also edit your original post to see what I did to fix it. Cheers!

Kim Gee
Kim Gee
3,841 Points

thank you Colin. I didn't know how to format the post.

1 Answer

Jeff Lemay
Jeff Lemay
14,266 Points

Not sure if this is your specific issue but want to throw out a common problem with using php's header function:

NOTHING can be printed to the page before you call the header function. If you have a blank line or even just a space before your opening php tag, the header will fail.

You also have the wrong kind of quotes around REQUEST_METHOD (”), should be ("). It shows a syntax error in sublime so that might be an issue.

Kim Gee
Kim Gee
3,841 Points

Thank you Jeff. It is working now.