title: prevent php mail sent going to spam gmail
body: <p>this is my complete code that I use to send emails from a contact form on a website.
  Despite all the best practices used (headers etc), the results are:</p>
  
  <p>1) the confirmation email to users goes in gmail spam every time and it is flaged as phishing</p>
  
  <p>2) the admin email is flagged as phishing</p>
  
  <p>Could someone help me? Thank you!</p>
  
  <pre><code>&lt;?
  // -----------------------------------------------------------------------------
  // Website info
  
      $SiteName = "www.example.com";
      $SiteWork = "Enterprise Name";
      $SiteMin = "Ent. name";
      $SiteEmail = "info@example.com";
      $SecondaryEmail = "admin@example.com";
      $ThankYouMessage = "$SiteMin - Message sent!";
      $SiteTel = "Tel (+39) 0XX.XXXXXXX";
      $SiteFax = "Fax (+39) 0XX.XXXXXXX";
      $SiteSocial = "#...";
      $SiteAddress = "...";
  
  // -----------------------------------------------------------------------------
  // Retrieve contents
  
      $UserSubject = $_POST['UserSubject'];
      $UserName = $_POST['UserName'];
      $UserCity = $_POST['UserCity'];
      $UserEmail = $_POST['UserEmail'];
      $UserComments = $_POST['UserComments'];
      $UserAuth = $_POST['UserAuth'];
  
  // -----------------------------------------------------------------------------
  // Set up user message
  
      $UserMessage = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;";
      $UserMessage .= "&lt;font size='6px'&gt;";
      $UserMessage .= "Ciao $UserName,";
      $UserMessage .= "&lt;/font&gt;&lt;br&gt;&lt;br&gt;";
      $UserMessage .= "&lt;font size='4px'&gt;";
      $UserMessage .= "abbiamo ricevuto il tuo messaggio.&lt;br&gt;";
      $UserMessage .= "Grazie per averci scritto, ti risponderemo al più presto.&lt;br&gt;&lt;br&gt;";
      $UserMessage .= "&lt;/font&gt;&lt;br&gt;";
      $UserMessage .= "&lt;img src='http://www.piazzaimpianti.it/img/logo.svg' width='60px'&gt;&lt;br&gt;&lt;br&gt;";
      $UserMessage .= "$SiteWork $SiteAddress&lt;br&gt;";
      $UserMessage .= "$SiteTel - $SiteName - $SiteSocial&lt;br&gt;";
      $UserMessage .= "$SiteName&lt;br&gt;";
      $UserMessage .= "&lt;/body&gt;&lt;/html&gt;";
  
      $UserHeaders = "From: $SiteEmail\r\n";
      $UserHeaders .= "Reply-To: $SiteEmail\r\n";
      $UserHeaders .= "Return-Path: $SiteEmail\r\n";
      $UserHeaders .= "CC:\r\n";
      $UserHeaders .= "BCC:\r\n";
      $UserHeaders .= "MIME-Version: 1.0\r\n";
      $UserHeaders .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
      $UserHeaders .= "X-Priority: 3\r\n";
      $UserHeaders .= "X-Mailer: PHP". phpversion() ."\r\n";
  
  // -----------------------------------------------------------------------------
  // Set up admin message
  
      $AdminMessage = "Messaggio:\n";
      $AdminMessage .= "\n";
      $AdminMessage .= "$UserComments\n";
      $AdminMessage .= "\n\n";
      $AdminMessage .= "-------------------------------------------------\n";
      $AdminMessage .= "Dati utente:\n";
      $AdminMessage .= "-------------------------------------------------\n";
      $AdminMessage .= "$UserName \n";
      $AdminMessage .= "$UserEmail \n";
      $AdminMessage .= "$UserCity \n";
      $AdminMessage .= "-------------------------------------------------\n";
      $AdminMessage .= "Autorizzi il trattamento dei dati ai sensi del D.lgs.196/03 (*)? $UserAuth \n";
      $AdminMessage .= "-------------------------------------------------\n";
      $AdminMessage .= "Puoi rispondere al messaggio di $UserName\n";
      $AdminMessage .= "scrivendo all'indirizzo: $UserEmail\n\n";
  
  // -----------------------------------------------------------------------------
  // Send confirmation to contact page
  
      $array['Sent'] = array('payload' =&gt; 'sent');
      echo json_encode($array);
  
  // -----------------------------------------------------------------------------
  // Send the emails
  
  // confirmation email to user
      mail($UserEmail, $ThankYouMessage, $UserMessage, $UserHeaders); 
  
  // email to admin
      mail("$SiteEmail", "$UserSubject", $AdminMessage, "From: $UserEmail"); 
  
  ?&gt;
  </code></pre>