title: Mail marked as spam by gmail alone by php mail() as well as smtp
body: <p>i have trying to send email to reset user password using php mail() but its sends to spam folder in Gmail Account alone in yahoo mail i can get this mail inside inbox. i googled and seen that some of the people says to use smtp mail server via phpmailer.</p>
  
  <p>i tried that too but i get same result as php mail() function did.. here my php mail() function code</p>
  
  <pre><code>$headers  = 'From: no-reply@mydomain.us' . "\r\n";
  $headers .= 'Reply-To: '.$to.'';
  $headers .= 'Subject: ' . $subject ." \r\n";
  $headers  = 'MIME-Version: 1.0' . "\r\n";
  $headers .= 'Content-type: text/html; charset="iso-8859-1"'. "\r\n";
  @mail($to, $subject, $msg, $headers);
  </code></pre>
  
  <p>and php mailer smtp code </p>
  
  <pre><code> date_default_timezone_set('Etc/UTC');
  
  require_once 'PHPMailerAutoload.php';
  
  $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 = 'mydomain.us';
  
  // use
  // $mail-&gt;Host = gethostbyname('smtp.gmail.com');
  // if your network does not support SMTP over IPv6
  //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  $mail-&gt;Port = 465;
  
  //Set the encryption system to use - ssl (deprecated) or tls
  $mail-&gt;SMTPSecure = 'ssl';
  
  //Whether to use SMTP authentication
  $mail-&gt;SMTPAuth = true;
  
  //Username to use for SMTP authentication - use full email address for gmail
  $mail-&gt;Username = "cs@mydomain.us";
  
  //Password to use for SMTP authentication
  $mail-&gt;Password = "pass";
  
  //Set who the message is to be sent from
  $mail-&gt;setFrom('cs@umydomain.us.us', 'sender name');
  
  //Set an alternative reply-to address
  $mail-&gt;addReplyTo('cs@mydomain.us', 'sender name');
  
  //Set who the message is to be sent to
  $mail-&gt;addAddress($to, 'John Doe');
  
  //Set the subject line
  $mail-&gt;Subject = $subject;
  
  //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;msgHTML($msg);
  
  //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('images/phpmailer_mini.png');
  
  //send the message, check for errors
  if (!$mail-&gt;send()) {
      echo "Mailer Error: " . $mail-&gt;ErrorInfo;
  } else {
      echo "Message sent!";
  }
  </code></pre>