WarMacheen Posted June 18, 2015 Share Posted June 18, 2015 I've been rearranging and changing things for a few hours and I can't get past this issue Warning: Cannot modify header information - headers already sent by (output started at /****/****/****/****/php/mailer.php:1) in /****/****/****/****/php/mailer.php on line 27 If I comment out the thanks.html header there isn't an error, but the code also doesn't redirect to the correct html page. I've also verified that there isn't any white space issues at the beginning and end of the code block <?php $myemail = "abcd@abcd.org"; $first_name = check_input($_POST['first_name'], "Enter your first name"); $last_name = check_input($_POST['last_name'], "Enter your last name"); $subject = "email from Dulles ISAC contact form"; $email = check_input($_POST['email']); $comments = check_input($_POST['comments'], "Write your message"); if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } $message = " First Name: $first_name Lirst Name: $last_name E-mail: $email Comments: $comments "; mail($myemail, $subject, $message); header('Location:thanks.html'); exit(); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <p>Please correct the following error:</p> <strong><?php echo $myError; ?></strong> <p>Hit the back button and try again</p> </body> </html> <?php exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/296900-php-headerredirect-help/ Share on other sites More sharing options...
mac_gyver Posted June 18, 2015 Share Posted June 18, 2015 since the output, that's causing the problem, is occurring on line 1 of the file and the only php code on that line is the php tag, you either have something in the file before the php tag or your file has been saved with utf-8 encoding and the BOM (Byte Order Mark) characters by your editor. insure that there's no characters before the first php tag and insure that your editor is saving the file without the BOM characters. Quote Link to comment https://forums.phpfreaks.com/topic/296900-php-headerredirect-help/#findComment-1514275 Share on other sites More sharing options...
WarMacheen Posted June 18, 2015 Author Share Posted June 18, 2015 since the output, that's causing the problem, is occurring on line 1 of the file and the only php code on that line is the php tag, you either have something in the file before the php tag or your file has been saved with utf-8 encoding and the BOM (Byte Order Mark) characters by your editor. insure that there's no characters before the first php tag and insure that your editor is saving the file without the BOM characters. The encoding was the problem, thank you. I changed to UTF-8 without signature, works Quote Link to comment https://forums.phpfreaks.com/topic/296900-php-headerredirect-help/#findComment-1514276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.