2

I am using php mail() to send email from my website. But I am facing strange behaviour.

  $headers  = "From: Saurabh Sharma <no-reply@example.com>\r\n";
  $headers .= 'Reply-To: ' . $email . "\r\n";
  $headers .= "Return-Path: me@example.com\r\n";
  $headers .= "Organization: Saurabh Sharma\r\n";
  $headers .= "X-Mailer: PHP\n";
  $headers .= "MIME-Version: 1.0" . "\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

But all the mails are landing in spam.

Also, I have added a rule on the server to send the copy of every mail to my personal email on gmail. I am able to receive the mail on gmail when I use php mail() (in spam) but can't see any mail on RoundCube on my server even if the receiving address is of my domain email address i.e me@example.com but I receive only the copy on gmail.

Also, If I send mails to/from Roundcube to my Gmail and vice versa, mail always lands in inbox in Gmail and Roundcube also shows the mail in inbox.

But strange things are happening in php mail();

The major issue is that email is not received on me@example.com but I can see the copy on Gmail.

Am I doing something wrong in headers?

Saurabh Sharma
  • 2,422
  • 4
  • 20
  • 41
  • 1
    Do you have an mx record that authenticates your webserver to send mails for `example.com`? – Forbs Aug 29 '16 at 04:49
  • gmail has checked the `from` mail id and if it's not a registered gmail id then everything goes to spam. check these links:- http://stackoverflow.com/questions/5935087/how-do-i-prevent-mails-sent-through-php-mail-from-going-to-spam and http://stackoverflow.com/questions/16352112/how-to-prevent-mail-from-going-to-spam – Alive to die - Anant Aug 29 '16 at 04:49
  • @Anant If I use Roundcube itself, The mails are received on gmail without any hassle. – Saurabh Sharma Aug 29 '16 at 04:53
  • @SaurabhSharma check the links that i have given to you. it will help you. Also some of non-gmail id's also worked(we can not list domains which will worked) – Alive to die - Anant Aug 29 '16 at 04:55
  • What about the 'reply to' that looks like a different email – Forbs Aug 29 '16 at 04:59
  • @Forbs Same code works fine on my other application on other server. – Saurabh Sharma Aug 29 '16 at 05:07
  • @Anant The issue is not that emails are landing in spam, but why I am not receiving mail on my server and instead I am only receiving a copy on Gmail – Saurabh Sharma Aug 29 '16 at 05:09
  • take a look at the headers of the 'good' emails and see what's different, I know you said you set the MX record, but it's how anti-spam sees if a server can send emails, i suspect your MX record is setup wrong. – Forbs Aug 29 '16 at 05:11

0 Answers0