This question already has an answer here:
- How to fix “Headers already sent” error in PHP 11 answers
- Reference - What does this error mean in PHP? 34 answers
I am sure you all know this error:
Warning: Cannot modify header information - headers already sent by (output started at /homepages/4/d374499247/htdocs/wp-content/themes/tyler/mail.php:1) in /homepages/4/d374499247/htdocs/wp-content/themes/tyler/mail.php on line 34
And this is the code:
if (strpos($email,'@') !== false) {
ob_start();
mail($to,$subject,$message,$headers);
header("Location: thankyou.html");
ob_end_flush(); }
Could anyone offer any help here? I just want it to mail() the information and then go to the Location page
EDIT: Here is the entire code..
<?php
$to = 'myemail@gmail.com';
$subject = 'בקשת הצטרפות לרשימת תפוצה';
$message =
'בקשת הצטרפות לרשימת תפוצה' . "\n\n" .
'שם: ' . $_REQUEST['name'] . "\n\n" .
'דואר אלקטרוני: ' . $_REQUEST['email'];
$email = $_REQUEST['email'];
$headers = 'From: ' . $email . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/plain; charset=ISO-8859-1";
// server-validation
if (strpos($email,'@') !== false){
mail($to,$subject,$message,$headers);
header("Location: thankyou.html");
} else {
echo "<p class='error'>כתובת הדוא'ל שגויה.</p>";
}
?>
It's most likely there's a whitespace of some sort before your PHP tags (as the output starats at the very first line).
There can't be ANY output before the
header()
, not even whitespaces or line breaks.This error is being caused by the fact that you have already sent data to the client at the moment you are trying to send the headers (which should be sent first).
Most likely, you have some whitespace in the beginning of your file. Based on your current code example, it is hard to say for sure what exactly is causing the problem, but based on the fact that the error says it is on line 1 in your file, I'd say its whitespace.
Check your page encoding. Probably it UTF-8+ (with UTF-8 signature)
If not then you need to check white spaces.