title: PHP form: Cannot modify header information - headers already sent
body: <p>I know that this question has been asked many times, however, I can't seem to find solutions that are relevant to my situation, since they mostly deal with wordpress.</p>
  
  <p>Here is my mail form:</p>
  
  <pre><code> &lt;?php 
   $to = "email@gmail.com" ; 
   $from = $_REQUEST['email'] ; 
   $name = $_REQUEST['name'] ; 
   $headers = "From: $from"; 
   $subject = "Contact Submission From domain.com"; 
  
   $fields = array(); 
   $fields{"name"} = "name"; 
   $fields{"title"} = "title"; 
   $fields{"email"} = "email"; 
   $fields{"phone"} = "phone"; 
   $fields{"prefer_phone"} = "pref_phone"; 
   $fields{"prefer_email"} = "pref_email";
   $fields{"message"} = "message";
   $fields{"referral"} = "referral"; 
  
   $body = "Here is their submitted message:\n\n"; foreach($fields as $a =&gt; $b){  $body .= sprintf("%20s: %s\n\n",$b,$_REQUEST[$a]); } 
  
   if($from == '') {print "You have not entered an email, please hit back and resubmit";} 
   else { 
   $send = mail($to, $subject, $body, $headers);
  
   if($send) 
   {header( "Location: http://www.domain.com/sent.html" );} 
   else 
   {print "We encountered an error sending your mail, please notify support@domain.com";} 
   }
   ?&gt;
  </code></pre>
  
  <p>The email sends just fine, but I get the titular error for the redirect:</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at /home/wills5/public_html/send_henry.php:1) in /home/wills5/public_html/send_email.php on line 23</p>
  
  <p>Edit: It was frickin' whitespace before line 1 apparently, thanks guys.</p>
  
  <blockquote>
    <p>If the message says the error is in line 1, then it is typically leading whitespace, text >or HTML before the opening 
  </blockquote>