I was working for my college website, and I wrote a php script that sends email using php mail function. But the problem is, all the emails that I send are going into the recipients spam/junk Folder.

In order to resolve it, I tried all the steps and answers for the similar issues in stackoverflow and serverfault website, but yet the problem is unresolved.

This is the php code for sending email:

$headers = "MIME-Version: 1.0\r\n"
  ."Content-Type: text/plain; charset=utf-8\r\n"
  ."Content-Transfer-Encoding: 8bit\r\n"
  ."From: =?UTF-8?B?". base64_encode($from_name) ."?= <$from_address>\r\n"
  ."X-Mailer: PHP/". phpversion();
$subject="Web Mail Testing";
$body="This is test Message";
mail($to, $subject, $body, $headers, "-fwebmaster@{$_SERVER['SERVER_NAME']}");
echo "The Mail is  SuccessFully Sent to :".$to;

I am also attaching the original email (that i received in my gmail account "riteshkumargupta1990@gmail.com")

Delivered-To: riteshkumargupta1990@gmail.com
Received: by with SMTP id i18csp146000bki;
        Wed, 21 Nov 2012 20:58:12 -0800 (PST)
Received: by with SMTP id pp4mr1119127pbc.72.1353560291776;
        Wed, 21 Nov 2012 20:58:11 -0800 (PST)
Return-Path: <webmaster@nitw.ac.in>
Received: from www.nitw.ac.in (www.nitw.ac.in. [])
        by mx.google.com with ESMTPS id sh10si3456960pbb.293.2012.
        (version=TLSv1/SSLv3 cipher=OTHER);
        Wed, 21 Nov 2012 20:58:11 -0800 (PST)
Received-SPF: pass (google.com: best guess record for domain of webmaster@nitw.ac.in designates as permitted sender) client-ip=;
Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of webmaster@nitw.ac.in designates as permitted sender) smtp.mail=webmaster@nitw.ac.in
Received: from www.nitw.ac.in (localhost.localdomain [])
    by www.nitw.ac.in (8.13.8/8.13.8) with ESMTP id qAM50M0h016190
    for <riteshkumargupta1990@gmail.com>; Thu, 22 Nov 2012 10:30:23 +0530
Received: (from nobody@localhost)
    by www.nitw.ac.in (8.13.8/8.13.8/Submit) id qAM50McG016189;
    Thu, 22 Nov 2012 10:30:22 +0530
Date: Thu, 22 Nov 2012 10:30:22 +0530
Message-Id: <201211220500.qAM50McG016189@www.nitw.ac.in>
X-Authentication-Warning: www.nitw.ac.in: nobody set sender to webmaster@nitw.ac.in using -f
To: riteshkumargupta1990@gmail.com
Subject: Web Mail Testing
X-PHP-Originating-Script: 0:mailer.php
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
From: =?UTF-8?B?d2VibWFzdGVy?= <webmaster@nitw.ac.in>
X-Mailer: PHP/5.3.5

This is test Message

Also while googling I found a reason for this sort of problem is server blacklisting, and I used this tool to test it.

I was shocked when the above tool test found my server in some blacklists. How this is the case, since the original mail that i attached above says ":Received-SPF: pass (google.com: best guess record for domain of webmaster@nitw.ac.in designates as permitted sender)

Also, if my server is blacklisted, then how can i find the reason for blacklist and how to resolve it?


Regarding the spam/junk mail folder issues, two things:

  1. You need to look at the mail host's guidelines and help for bulk senders. Gmail's is here. Once you do everything they recommend, if your email's still getting marked as spam, ask them for help/support.

  2. Check your emails against a spam checker. There are free online tools available, you can run them against your spam filter of choice, etc., and work on getting the spam score as low as possible.

Regarding the blacklist:

  1. The tool you linked to checked against 45 different (relatively widely used) blacklists. Gmail does not use any of the 3 your server was blacklisted on.

  2. To get off a blacklist, you generally need to contact the organization that maintains it, plead your case, and get them to take you off. They'll also be the only ones able to tell you how you got on their specific blacklist.

    • The reasons for a mail server being blacklisted are usually either that enough people complained to them about emails coming from your server, or they discovered your server to be an open-relay, or otherwise possibly compromised by spammers.

    • There are people and businesses that will do the de-blacklisting work for you, usually for a very sizeable fee.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.