Question: I have created a form on php that writes the result on a .txt file.

What happens is that on my server all is working good, but on another server there is the following error: 

> 
> Warning: Cannot modify header information - headers already sent by (output started at /home1/alertme/public\_html/mavala/form.php:43) in /home1/alertme/public\_html/mavala/form.php on line 52
> 
> 
> 

The code I am using is:

```
<?php
    if(isset($_POST['submit']))
    {
      $name = $_POST['name'];
      $email = $_POST['email'];
      $new_content = "\r\nNome: " . $name;
      $new_content .= "\r\nEmail: " . $email;
      file_put_contents('emaillist.txt', $new_content, FILE_APPEND);
      print_r(error_get_last());
      header('Location: thank-you.html');    //This is line 52
    exit();
    }
    ?>

```

The link of the server with the error is: <http://trendalert.me/mavala/form.php>

After filling the form and submit, the php writes the result on the .txt file but does not show the thank you page: <http://trendalert.me/mavala/thank-you.html>

Again, on my side it´s all working, but on the clients´server is not.

Answer: 
```
    <?php

```

is your issue, its sending white space which sends the headers.

Make sure that `<?php` is the very first thing in a php file 

also on a production server, them warnings should be suppressed
Use the code below:

```
<?php
if(isset($_POST['submit']))
{
  $name = $_POST['name'];
  $email = $_POST['email'];
  $new_content = "\r\nNome: " . $name;
  $new_content .= "\r\nEmail: " . $email;
  file_put_contents('emaillist.txt', $new_content, FILE_APPEND);
  print_r(error_get_last());
  echo '<meta http-equiv="refresh" content="0; url=thank-you.html">';   //This is line 52
exit();
}
?>

```