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

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,268 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.