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 Redirecting After a Form Submission

PHP header not redirecting

Okay so, ive tried reading all the different discussions to try help me, but I cant seem to find anything (maybe its there, and im just not picking it up).

Everything woks fine up until I add in the header(Location: "contact-thanks.php").

Thanks in advance! :)

contact-process.php

<?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."Mesage: ".$message;


// TODO: Send Email 

header("Location: contact-thanks.php");
?>

contact-thanks.php

<?php

$pageTitle = "Contact Mike";
$section = "contact";
include("inc/header.php")

?>

    <div class="section page">
        <div class="wrapper">

            <h1>Contact</h1>

            <p>Thanks for the email! I&rsquo;ll be in touch shortly.</p>

        </div>
    </div>

<?php include("inc/footer.php"); ?>

4 Answers

Make sure you have set the name of your file correctly. 404 Error shows up when the page can't be found.

Thanks Mike!

I found it just before I read your comment, and your comment backed it up!. I had my file saved as

"contact.-thanks.php" instead of "contact-thanks.php"

Little typo had me running around, thanks for the help!

Hello Jamaal!

The function header needs a String as a required parameter. You must pass the string to the function as follows:

header("Location: contact-thanks.php");

Hope it helps!

Hi Hugo! :)

Thanks for the fast reply.

I've posted my code up above. I realise I did have it as you specified, can you plesae check over my code and see if theres anything wrong?

When I click submit, it goes to a page that says "object no found... etc... "

Thanks

I do not see any problems in the code. But maybe you could try to show errors that may be generating your application. You could add the following lines at the beginning of your PHP file temporarily.

ini_set('display_errors', 1);
error_reporting(E_ALL);

I added in the line of code like you said? im wondering if my position is right?. Im not sure what its doing , but I cant see it making any difference.

<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

$pageTitle = "Contact Mike";
$section = "contact";
include("inc/header.php");

?>

    <div class="section page">
        <div class="wrapper">

            <h1>Contact</h1>

            <p>Thanks for the email! I&rsquo;ll be in touch shortly.</p>

        </div>
    </div>

<?php include("inc/footer.php"); ?>

p.s thanks for the hlep

I see, maybe the semicolon after including the header:

include("inc/header.php");

I have corrected that now, but problem still happens. Object not found.... Error 404... etc

include("inc/header.php");