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

When I hit the send button it sends the email then comes up with just the header and no thank you message

https://w.trhou.se/b85qgslckh

I don't understand why i cant get the thank you message to come up

1 Answer

Sjors Theuns
Sjors Theuns
6,091 Points

Hi James,

when using headers in PHP make sure there is NO output before you call the header function.

In your case you have the line:

header("Location:index.php?status=thanks");

But you also include your header file with:

include('inc/header.php');

This file contains output (in this case some html code) causing your header function to fail. From the PHP documentation:

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

thank you for your help I'm slowly getting the hang of this!