Log in

View Full Version : Resolved Getting blank page after program runs



mcolton
06-16-2014, 03:53 PM
I run my php program, update my database, and send some emails. After that, I want to return to my front page. The end of my program is:

mail($to,$subject,$message,$emailheader);
mail($to2,$subject,$message2,$emailheader);
header('Location: index.htm');
?>

If I leave out the "header" line, the emails are sent but I get a blank page that I have to back out of.
If I leave it in, the emails are still sent but I get error message:
Warning: Cannot modify header information - headers already sent by (output started at /home/xxxx/public_html/pdoinfoupdate2.php:2) in /home/xxxx/public_html/pdoinfoupdate2.php on line 87 (line 87 is the header line)

I've tried exit, die, and a hundred different things. Any help would be useful

fastsol1
06-16-2014, 08:55 PM
The error occurs when you have output to the browser before using the header(). Meaning ANYTHING, including doctype, <html>, etc, that is produced and output to the browser in the source code before the header() will cause this error. You need to do all your php processing before any output. The other more frowned upon way to fix it is to put this line at the very top of the page above everything else that your site includes(), requires(), etc.

ob_start();