-1

I mail using php mail function to send e-mail. In my dev server its working fine but in live server e-mail goes to spam folder.

<?php
    $to = "example@gmail.com";
    $subject = "Registration";
    $from = "example1@gmail.com";
    $content = "Test";
    $headers = "From: Test <" . strip_tags($from) . ">\r\n";
    $headers .= "MIME-Version:1.0" ."\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
    $res = mail($to,$subject,$content,$headers);

    $headers = "From: Test <" . strip_tags($to) . ">\r\n";
    $headers .= "MIME-Version:1.0" ."\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";
    $res2 = mail($from,$subject,$content,$headers);
DRUPWAY
  • 345
  • 6
  • 16

1 Answers1

0

The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.

Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.

Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.

https://github.com/PHPMailer/PHPMailer

answered by mrdognose

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

Prevent sent emails treated as junk mails using php mail function

Community
  • 1
  • 1
Sarath
  • 2,318
  • 1
  • 12
  • 24
  • Can i able to fix this issue by doing any changes on my live server? – DRUPWAY Jan 14 '15 at 12:58
  • for your server issues contact your server co-ordinators.. fixing the correct header solves the issue or use PHPMailer. – Sarath Jan 14 '15 at 13:00