title: php mailheaders vs header on website email from
body: <p>I am new to php and stackoverflow and I am trying to figure out a simple website contact form. I have the form and email functioning properly, but I have one nagging issue I can't figure out.  </p>
  
  <p>When the email is sent, the from email says myusername@p3pxxxxxx.com which is my server. When I direct the email to my domain based email account, they don't get to my inbox, I bet the spam filters are stopping the odd email address.  So I tried sending it to my gmail inbox, which worked, but I don't check that email regularly.  I'd rather have it go to my domain based email account.</p>
  
  <p>So, I am looking for a way to edit the 'from' email address.  Instead of the user/server I would like it to use a real email address, mine or the person that sent it would be even better.  Here are a couple of attempts and what I currently have, none of which worked.</p>
  
  <p>Couple of Attempts:</p>
  
  <p>Attempted to pull the email address entered my sender.</p>
  
  <pre><code>//$mailheader = "From: ".$_POST["email"]."\r\n"; 
  //$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
  </code></pre>
  
  <p>This was another attempt.</p>
  
  <pre><code>//$mailheaders = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
  </code></pre>
  
  <p>What I currently have:</p>
  
  <pre><code>&lt;?
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $message = $_POST['message'];
  $security = $_POST['security'];
  
  $to = "myemailaddress@gmail.com";
  $subject = "Contact Message from Website";
  $mailheaders = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
  $message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
  
  
  if ($security=="10") {
      mail($to,$subject,$message,$mailheaders);
      header("Location:contact.php?s=1");
  }
  else {
      header("Location:contact.php?s=2");
  }
  ?&gt;
  </code></pre>
  
  <p>Followed the suggestion. Last attempt still didn't work...</p>
  
  <pre><code>&lt;?
  $name = $_POST['name'];
  $email = $_POST['email'];
  $phone = $_POST['phone'];
  $message = $_POST['message'];
  $security = $_POST['security'];
  
  $to = "mail@example.com";
  $subject = "Contact Message from Website";
  $message = "A visitor of exampledomain.com has submitted the following message.\n\nName: $name\n\nEmail: $email\n\nPhone: $phone\n\nMessage: $message";
  $mailheaders = "From: webmaster@example.com\r\nReply-To: website@example.com";
  
  if ($security=="10") {
      mail($to,$subject,$message,$mailheaders);
      header("Location:contact.php?s=1");
  }
  else {
      header("Location:contact.php?s=2");
  }
  ?&gt;
  </code></pre>