-3

Hi I'm wrinting a simple mail script in PHP

  • Of what that I found every one says its probably a whitespace in front of

But as you can see I can't find anything like the solutions on the internet in my code...

The error says : output started at /customers/e/e/5//httpd.www/email.php:1)

<?php
$to = '...@gmail.com';
$subject = $_POST['subject'];  
$message = $_POST['message'];  
$firstName = $_POST['firstName'];  
$lastName = $_POST['lastName'];  
$email = $_POST['email'];  
mail($to, "Contact www....com: $subject", "Gecontacteerd van de website: www.....com\nZender: $firstName $lastName\nBericht: $message", "From: $email");
header("Location:http://www.....com");  
exit;
?>
dg90
  • 1,223
  • 3
  • 16
  • 28

2 Answers2

3

No output before sending headers

Functions that send/modify HTTP headers must be invoked before any output is made. Otherwise the call fails:

Warning: Cannot modify header information - headers already sent (output started at file:line)

Some functions modifying the HTTP header are:

Output can be:

  • Unintentional:
  • Intentional:
    • print, echo and other functions producing output (like var_dump)
    • Raw <html> areas before <?php code.

Hint : for checking this, press crtl+u on the page to see the source, and check if the error is in line 2 , or there is a space before it.

Alireza Fallah
  • 4,411
  • 3
  • 27
  • 55
0

It's not just whitespace. You can't send any data at all to the client (i.e. anything outside <?php ?> tags) before you call header().

What you need to do is move your PHP code to the top of the file, before any of the HTML code (although in this case it looks like you're not actually expecting any HTML output from this script anyway, so you can probably get rid of it entirely).

Peter Bloomfield
  • 5,009
  • 22
  • 34