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

Adam Soucie
PLUS
Adam Soucie
Courses Plus Student 8,710 Points

Redirecting After a Form Submission - Not functioning

Every time I try to redirect using the following code, I get a blank page save for the error message below. Anyone able to figure out what I'm doing wrong?

Code:

// SEND THE EMAIL
if($mail->Send())
{
    header("Location: " . BASE_URL . "contact/thanks.php");
    exit;
}

Error:

Warning: Cannot modify header information - headers already sent by (output started at /home/content/72/10763172/html/contact/index.php:8) in /home/content/72/10763172/html/contact/index.php on line 92

2 Answers

Adam Soucie
PLUS
Adam Soucie
Courses Plus Student 8,710 Points

UGH. Found the problem. PHP reeeeeeeeally hates whitespace, even if it's before the file starts for stuff like comments. Grr.

Here's a much more detailed explanation that finally helped me through it. http://stackoverflow.com/questions/8028957/headers-already-sent-by-php

Nicholas Read
Nicholas Read
2,958 Points

Thanks for this! Exactly what I needed! I had a blank line at the top of my php file that was breaking the header redirect.