-1

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>";
}
?>
Amit
  • 7,688
  • 17
  • 53
  • 68
  • The question seems a duplicate, but I have utilized all possible solutions. The final solution was changing the encoded format. – Amit Dec 30 '11 at 09:30

3 Answers3

5

Check your page encoding. Probably it UTF-8+ (with UTF-8 signature)

If not then you need to check white spaces.

Narek
  • 3,813
  • 4
  • 42
  • 58
2

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.

Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
1

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.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308