title: PHP contact form sends message through senders address
body: <p>Recently I've been having problems with my PHP contact form. It's worked great for about two years, and I haven't changed anything, so I don't really understand what the problem is. Here's the code:</p>
  
  <pre><code>&lt;?php 
  
          // Check for header injections
          function has_header_injection($str) {
              return preg_match ( "/[\r\n]/", $str );
          }
  
          if(isset ($_POST['contact_submit'])) {
  
              $name   = trim($_POST['name']);
              $email  = trim($_POST['email']);
              $tel    = trim($_POST['tel']);
              $msg    = $_POST['message'];
  
              // check to see if name or email have header injections
              if (has_header_injection($name) || has_header_injection($email)){
  
                  die();          
  
              }
  
              if ( !$name || !$email || !$msg ) {
  
                  echo '&lt;h4 class="error"&gt;All Fields Required&lt;/h4&gt;&lt;a href="page.php"  target="_blank" class="button link"&gt;Go back and try again&lt;/a&gt;';
                  exit;
  
              }   
  
              // add the recipient email to a variable
              $to = "example@example.net";
  
              // Create a subject
              $subject = "$name sent you an email";
  
              // construct your message
              $message .= "Name: $name sent you an email\r\n";
              $message .= "Telephone: $tel\r\n";
              $message .=  "Email: $email\r\n\r\n";
              $message .=  "Message:\r\n$msg";
  
  
  
              $message = wordwrap(message, 72);
  
              // set the mail header
              $headers = "MIME=Version: 1.0\r\n";
              $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
              $headers .= "\r\nFrom: " . $name . " \r\n\r\n" . $tel . " \r\n\r\n " . $msg . "\r\n\r\n &lt;" . $email . "&gt; \r\n\r\n";
              $headers .= "X-Priority: 1\r\n";
              $headers .= "X-MSMail-Priority: high\r\n\r\n";
  
              // Send the Email
              mail( $to, $subject, $message, $headers );      
  
          ?&gt;
  
          &lt;!--- END PHP CONTACT FORM --&gt;
  
          &lt;!-- Show Success message --&gt;
          &lt;h2&gt;Thanks for contacting Us!&lt;/h2&gt;
          &lt;p align="center"&gt;Please allow 24 hours for a response&lt;/p&gt;
          &lt;p&gt;&lt;a href="index.php" class="button block"&gt;&amp;laquo; Go to Home Page&lt;/a&gt;&lt;/p&gt;
  
          &lt;?php } else { ?&gt;
  
          &lt;form method="post" action="" id="contact-form"&gt;
  
              &lt;label for="name"&gt;Your Name&lt;/label&gt;
              &lt;input type="text" id="name" name="name"&gt;
  
              &lt;label for="tel"&gt;Your Phone Number&lt;/label&gt;
              &lt;input type="tel" id="tel" name="tel"&gt;
  
              &lt;label for="email"&gt;Your Email&lt;/label&gt;
              &lt;input type="email" id="email" name="email"&gt;
  
              &lt;label for="message"&gt;the date/time you wish to sign up for&lt;/label&gt;
              &lt;textarea id="message" name="message"&gt;&lt;/textarea&gt;
              &lt;br&gt;
  
              &lt;input type="submit" class="button next" name="contact_submit" value="Sign Up"&gt;
  
  
  
  
          &lt;/form&gt;
  
          &lt;?php } ?&gt;
  </code></pre>
  
  <p>However, when the contact form is submitted, instead of sending the information to the body of the email, it sends it in the "From" section of the email. For example, the email might say:</p>
  
  <p>To: Web Developer</p>
  
  <p>From: Bob Smith 888-888-8888 mondays, wednesdays fridays</p>
  
  <p>Subject: Bob Smith sent you an email!</p>
  
  <p>Body: 
  
  X-Priority: 1X-MSMail-Priority: high</p>
  
  <p>message</p>
  
  <p>I don't really know what's going on, so any help would be appreciated!</p>