2

I'm using PHP mail() function to send out mails using my script. It goes as:

$headers = "From: registration@tutorsvilla.com\r\n"; 
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message="Thanks a lot for registering on TutorsVilla.";
mail($email,"Email Verification-TutorsVilla",$message,$headers,'-        
freturn@tutorsvilla.com');

But even after having a registered email account on the web host, my mails are landing in spam. Why is that so?

j08691
  • 204,283
  • 31
  • 260
  • 272
  • 3
    This might not have to do with the PHP as much as the content that the spam filters are picking up on. Maybe try changing the content – Zachary Weixelbaum Jul 06 '15 at 17:10
  • 4
    http://stackoverflow.com/questions/4623278/php-mail-function-gets-spam-email?rq=1 and http://stackoverflow.com/questions/11280030/php-mail-goes-to-junk-possible-dns-issue?rq=1 and http://stackoverflow.com/questions/16762634/my-mails-are-sent-as-spam-i-use-php-mail and http://stackoverflow.com/questions/371/how-do-you-make-sure-email-you-send-programmatically-is-not-automatically-marked – j08691 Jul 06 '15 at 17:11
  • 3
    Sending emails is a complex issue, and not well handled by PHP’s `mail` function (not unless you put a lot of additional effort into it). Do yourself a favor, and use a dedicated mailer class, such as PHPMailer or Swift Mailer instead. – CBroe Jul 06 '15 at 17:12
  • "I'm using PHP mail() function to send out mails" <-- that's your problem. Use a mailer class. – bishop Jul 06 '15 at 17:13
  • I've been there and done that, and @CBroe comment is absolutely the way forward. PHPMailer FTW – Martin Jul 06 '15 at 17:13
  • Alright, I'll try the PHP mailer class. Also, is the mail being sent through the dedicated server? Because, it doesn't really matter whether or not your sending email address is registered or not, it sends mail anyway. – Harsh S. Kulshrestha Jul 06 '15 at 17:20
  • [Swift Mailer](http://swiftmailer.org/) which is default with symfony is really good. With a small config change / transport class change you can set it to just save mails on disk instead of sending out to debug etc. – OIS Jul 06 '15 at 17:21
  • You can try [Mandrill](https://www.mandrill.com/) ! It has a dead-simple config, good documentation and 12k/month free emails ! – Themis Beris Jul 06 '15 at 18:34

3 Answers3

0

It has not to do with your php mail function,

There can be many reasons for your mail going to spam:

1.)The headers that you set in your mail,

2.) The content of you mail body,

3.)The subject of your mail,

4.)If you domain name or your public IP address is black listed in organisations like spam hause.

Suggestion: You can use the PHPMailer plugin for php for sending mails.

Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
0

Try the below email script, and always be careful with the subject text, as the subject text can always land an email in spam.

$to      = 'freturn@tutorsvilla.com';

$subject = 'TutorsVilla Email';

$message = 'Thanks a lot for registering on TutorsVilla.';

$headers = 'From: registration@tutorsvilla.com' . "\r\n" .
'Reply-To: registration@tutorsvilla.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
0

many emails server block emails only in html, if this is your case you can send multipart mimed messages and take care of this restriction. also important is send the correct headers and that you sendmail software (mercury in most cases) should be well configured.

read this information to build a correct email message Don't Open this link!! Noooooo!!

Let me know if this was helpful for you.

Jjsg08
  • 124
  • 11