title: Contact form (PHP and Ajax): how to print data on e-mail?
body: <p>I'm new to PHP and I'm having a hard time trying to understand how to print data on e-mail.</p>
  
  <p>I need all data sent to my e-mail, something like this:</p>
  
  <p>Nome: <em>shows me the name written in the field</em></p>
  
  <p>E-mail:  <em>shows me the e-mail written in the field</em></p>
  
  <p>Telefone:  <em>shows me the phone number written in the field</em> </p>
  
  <p>Mensagem:  <em>shows me the message written in the field</em></p>
  
  <p>Right now it's only sending me the name and the message, and without the "label" Nome and Mensagem that I need.</p>
  
  <p>How can I achieve this?</p>
  
  <p>Form: <a href="http://baskra.com/teste/teste.html" rel="nofollow">http://baskra.com/teste/teste.html</a></p>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  
  header('Content-Type: text/html; charset=UTF-8');
  
  if($_POST)
  {
      //check if its an ajax request, exit if not
      if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
          die();
      } 
  
      $to_Email       = "giovanna.coppola@yahoo.com"; //Replace with recipient email address
      $subject        = 'Formulário de Contato (Site)'; //Subject line for emails
  
      //check $_POST vars are set, exit if any missing
      if(!isset($_POST["userName"]) || !isset($_POST["userEmail"]) || !isset($_POST["userPhone"]) || !isset($_POST["userMessage"]))
      {
          die();
      }
  
      //Sanitize input data using PHP filter_var().
      $user_Name        = filter_var($_POST["userName"], FILTER_SANITIZE_STRING);
      $user_Email       = filter_var($_POST["userEmail"], FILTER_SANITIZE_EMAIL);
      $user_Phone       = filter_var($_POST["userPhone"], FILTER_SANITIZE_STRING);
      $user_Message     = filter_var($_POST["userMessage"], FILTER_SANITIZE_STRING);
  
      //additional php validation
      if(strlen($user_Name)&lt;6) // If length is less than 6 it will throw an HTTP error.
      {
          header('HTTP/1.1 500 Nome muito curto ou campo vazio.');
          exit();
      }
      if(!filter_var($user_Email, FILTER_VALIDATE_EMAIL)) //email validation
      {
          header('HTTP/1.1 500 Insira um e-mail válido.');
          exit();
      }
      if(!is_numeric($user_Phone)) //check entered data is numbers
      {
          header('HTTP/1.1 500 Esse campo só aceita números.');
          exit();
      }
      if(strlen($user_Message)&lt;10) //check emtpy message
      {
          header('HTTP/1.1 500 Mensagem curta demais.');
          exit();
      }
  
      //proceed with PHP email.
      $headers = 'From: '.$user_Email.'' . "rn" .
      'Reply-To: '.$user_Email.'' . "rn" .
      'X-Mailer: PHP/' . phpversion();
  
  
      @$sentMail = mail($to_Email, $subject, $user_Message .'  -'.$user_Name, $headers);
  
      if(!$sentMail)
      {
          header('HTTP/1.1 500 Não foi possível enviar. Tente novamente.');
          exit();
      }else{
          echo 'Olá, '.$user_Name.'. Agradecemos o contato! ';
          echo 'Retornaremos o mais breve possível.';
      }
  }
  ?&gt;
  </code></pre>