title: PHPMailer doesn't send mail to gmail
body: <p>I am trying to send mail through PHPMailer. Everything seems to work fine, but the mails sent to my email do not show on gmail (when using google apps) but shows in Outlook or Mobile Email. I think I'm going wrong with the headers somewhere. Please help me.</p>
  
  <p>Tried this <a href="https://stackoverflow.com/questions/11856139/phpmailer-not-sending-mail-to-gmail">question</a> first but got no answer.</p>
  
  <p><strong>PHPMailer File</strong>:</p>
  
  <pre><code>&lt;?php
  
  require('PHPMailer/class.phpmailer.php');
  
  if(isset($_POST['email'])) {
  
      // EDIT THE 2 LINES BELOW AS REQUIRED
      //$email_to = "info@rsadvisories.com";
      //$email_subject = "Request for Portfolio check up from ".$first_name." ".$last_name;
  
      $title = array('Title', 'Mr.', 'Ms.', 'Mrs.');
      $selected_val = $_POST['title'];
      $first_name = $_POST['first_name']; // required
      $last_name = $_POST['last_name']; // required
      $email_from = $_POST['email']; // required
      $telephone = $_POST['telephone']; // not required
      $comments = $_POST['comments']; // required
  
      function clean_string($string) {
        $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
      }
       $email_message = "Name: ".$selected_val." ".clean_string($first_name)." ".clean_string($last_name)."&lt;br /&gt;Email id: ".clean_string($email_from)."&lt;br /&gt;Telephone no: ".clean_string($telephone)."&lt;br /&gt;Details: ".clean_string($comments);
      $allowedExts = array("doc", "docx", "xls", "xlsx", "pdf");
  $temp = explode(".", $_FILES["file"]["name"]);
  $extension = end($temp);
  if ((($_FILES["file"]["type"] == "application/pdf")
  || ($_FILES["file"]["type"] == "application/msword")
  || ($_FILES["file"]["type"] == "application/excel")
  || ($_FILES["file"]["type"] == "application/vnd.ms-excel")
  || ($_FILES["file"]["type"] == "application/x-excel")
  || ($_FILES["file"]["type"] == "application/x-msexcel")
  || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
  || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) &amp;&amp; ($_FILES["file"]["size"] &lt;= 20000)
  &amp;&amp; in_array($extension, $allowedExts))
    {
    if ($_FILES["file"]["error"] != 0)
      {
      echo "&lt;script&gt;alert('Error: " . $_FILES["file"]["error"] ."')&lt;/script&gt;";
      }
    else
      {
          $d='upload/';
          $de=$d . basename($_FILES['file']['name']);
      $u=move_uploaded_file($_FILES["file"]["tmp_name"], $de);
  $fileName = $_FILES['file']['name'];
      $filePath = $_FILES['file']['tmp_name'];
       //add only if the file is an upload
       //if($u)
       //echo "Uploaded!";
       }
    }
    elseif (!(file_exists($_FILES['file']['tmp_name'])) || !(is_uploaded_file($_FILES['file']['tmp_name']))) 
  {
  echo "&lt;script&gt; alert('Warning : No file uploaded, Email will be sent without attachments');&lt;/script&gt;";
  }
  else
    {
  
    die("&lt;script&gt;alert('Invalid file'); window.location.href='main.php';&lt;/script&gt;");
    }
  
  // create email headers
  $headers = 'From: '.$email_from."\r\n".
  'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  //Create a new PHPMailer instance
  $mail = new PHPMailer();
  //Tell PHPMailer to use SMTP
  $mail-&gt;IsSMTP();
  //Enable SMTP debugging
  // 0 = off (for production use)
  // 1 = client messages
  // 2 = client and server messages
  $mail-&gt;SMTPDebug  = 2;
  //Ask for HTML-friendly debug output
  $mail-&gt;Debugoutput = 'html';
  //Set the hostname of the mail server
  $mail-&gt;Host       = "***";
  //Set the SMTP port number - likely to be 25, 465 or 587
  $mail-&gt;Port       = 25;
  //Whether to use SMTP authentication
  $mail-&gt;SMTPAuth   = false;
  //Username to use for SMTP authentication
  $mail-&gt;Username   = "***";
  //Password to use for SMTP authentication
  $mail-&gt;Password   = "***";
  //Set who the message is to be sent from
  $mail-&gt;SetFrom($email_from, $first_name.' '.$last_name);
  $mail-&gt;AddCustomHeader($headers);
  //Set an alternative reply-to address
  //$mail-&gt;AddReplyTo('replyto@example.com','First Last');
  //Set who the message is to be sent to
  $mail-&gt;AddAddress('***', 'Ritu Shah');
  $mail-&gt;From=$email_from;
  //Set the subject line
  $mail-&gt;Subject = 'Request for Portfolio Check up';
  //Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body
  $mail-&gt;Body=$email_message;
  //Replace the plain text body with one created manually
  $mail-&gt;AltBody = 'This is a plain-text message body';
  //Attach an image file
  //$mail-&gt;AddAttachment($file);
  $mail-&gt;AddAttachment($de);
  //Send the message, check for errors
  if(!$mail-&gt;Send()) {
    echo "&lt;script&gt;alert('Mailer Error: " . $mail-&gt;ErrorInfo."')&lt;/script&gt;";
  } else {
      die();
      $headers1 = 'From: ***'."\r\n".
  'Reply-To: ritu@rsadvisories.com'."\r\n" .
  'X-Mailer: PHP/' . phpversion();
     mail($email_from,'Re:Request for Portfolio Check up','We Have received your mail. We will contact you soon.',$headers1);
     echo "&lt;script&gt;alert('Your request has been submitted. We will contact you soon.');window.location.href='main.php';&lt;/script&gt;";
  }
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Debug message</strong> (no file uploaded, hence could not access file):</p>
  
  <pre><code>Could not access file: 
  SMTP -&gt; FROM SERVER:220-gator1545.hostgator.com ESMTP Exim 4.80 #2 Tue, 03 Sep 2013 11:35:53 -0500 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
  CLIENT -&gt; SMTP: EHLO rsadvisories.com
  SMTP -&gt; FROM SERVER: 250-gator1545.hostgator.com Hello rsadvisories.com [216.172.167.28]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
  CLIENT -&gt; SMTP: MAIL FROM:&lt;ayushkster@gmail.com&gt;
  SMTP -&gt; FROM SERVER:250 OK
  CLIENT -&gt; SMTP: RCPT TO:&lt;ritu@rsadvisories.com&gt;
  SMTP -&gt; FROM SERVER:250 Accepted
  CLIENT -&gt; SMTP: DATA
  SMTP -&gt; FROM SERVER:354 Enter message, ending with "." on a line by itself
  CLIENT -&gt; SMTP: Date: Tue, 3 Sep 2013 11:35:53 -0500
  CLIENT -&gt; SMTP: Return-Path: &lt;ayushkster@gmail.com&gt;
  CLIENT -&gt; SMTP: To: Ritu Shah &lt;ritu@rsadvisories.com&gt;
  CLIENT -&gt; SMTP: From: Ayush Khemka &lt;ayushkster@gmail.com&gt;
  CLIENT -&gt; SMTP: Subject: Request for Portfolio Check up
  CLIENT -&gt; SMTP: Message-ID: &lt;cb1ac1dd52e8724a2e536ea35058be19@rsadvisories.com&gt;
  CLIENT -&gt; SMTP: X-Priority: 3
  CLIENT -&gt; SMTP: X-Mailer: PHPMailer 5.2.6 (https://github.com/PHPMailer/PHPMailer/)
  CLIENT -&gt; SMTP: From: ayushkster@gmail.com
  CLIENT -&gt; SMTP: Reply-To: ayushkster@gmail.com
  CLIENT -&gt; SMTP: X-Mailer: PHP/5.2.17
  CLIENT -&gt; SMTP: MIME-Version: 1.0
  CLIENT -&gt; SMTP: Content-Type: multipart/alternative;
  CLIENT -&gt; SMTP: boundary="b1_cb1ac1dd52e8724a2e536ea35058be19"
  CLIENT -&gt; SMTP: Content-Transfer-Encoding: 8bit
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19
  CLIENT -&gt; SMTP: Content-Type: text/plain; charset=iso-8859-1
  CLIENT -&gt; SMTP: Content-Transfer-Encoding: 8bit
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: This is a plain-text message body
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19
  CLIENT -&gt; SMTP: Content-Type: text/html; charset=iso-8859-1
  CLIENT -&gt; SMTP: Content-Transfer-Encoding: 8bit
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: Name: Mr. Ayush Khemka&lt;br /&gt;Email id: ayushkster@gmail.com&lt;br /&gt;Telephone no: 09930754012&lt;br /&gt;Details: 
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: --b1_cb1ac1dd52e8724a2e536ea35058be19--
  CLIENT -&gt; SMTP: 
  CLIENT -&gt; SMTP: .
  SMTP -&gt; FROM SERVER:250 OK id=1VGta5-0001jH-9P
  CLIENT -&gt; SMTP: quit
  SMTP -&gt; FROM SERVER:221 gator1545.hostgator.com closing connection
  </code></pre>