0

My code looks like this

$to = "mymailid@gmail.com";
$subject = "sample subject";
$body = "<div> hi hi .. </div>";
$headers = "Reply-To: The Sender <mymailid@gmail.com>\r\n"; 
$headers .= "Return-Path: The Sender <mymailid@gmail.com>\r\n";
$headers .= "From: The Sender <mymailid@gmail.com>\r\n"; 
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

mail($to, $subject, $body,$headers)

I have sent the suitalbe header in my mail function. Everytime when i run this code, my mail will go to the spam folder in my gmail account.. How do i avoid my mail going to spam folder?

Matarishvan
  • 2,382
  • 3
  • 38
  • 68
  • 1
    Check this answer, [http://stackoverflow.com/a/24644450/5517143](http://stackoverflow.com/a/24644450/5517143) – Rajdeep Paul Feb 08 '16 at 10:26
  • There's loads of reasons for mail getting treated as spam. Try using https://www.mail-tester.com/ to check yours. One pretty huge thing for you will be that you're sending mail unauthenticated. Try using PHPMailer or something, through an SMTP server – Jonathon Feb 08 '16 at 10:26

1 Answers1

0

It can fixed by passing complete header information informing the mail provider as the sender is a trusted domain (https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail) also some DNS settings involved.
You can find the detail information here:

http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/

https://www.digitalocean.com/community/questions/email-goes-to-spam-gmail-php