4

I have this funny thing. When I send an email out, to yahoo, gmail or hotmail users. If I include a link, it will treat as spam mail. But if i removed the link, it will become "inbox", not spam mail. Weird huh??

Is there anything to do with my mail server?? How to prevent my email to be treat as spam mail? I need link in my email content :)

php code:

// Send Email to the user
$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";

// Email Variables

$toUser  = '[email protected]'; // recipient
$subject = "Subject HERE!!"; // subject
$body    = '<div style="font-family:Arial; color:#333;">
                Some content here ...
        <a href="www.google.com" target="_blank"> Link here</a> 
        </div>';

if(mail($toUser,$subject,$body,$headers)){
    echo "Email SENT" . '<br>';
} else {
    echo "Email cannot sent" . '<br>';
};

5 Answers 5

4

At a guess, the mail servers calculate a spam score for each of your messages based on text analysis and a whole raft of other things that they won't tell anyone about - +3 for having non-words in the title, +2 for embedded links, etc etc. Chances are, the regular score for one of your generated emails (link free) is fairly high, but still low enough for the mail to get through.

Some anti-spam solutions are nice enough to stick the spam score in the message headers - look for something like "X-Spam-Score" in there. If you can find out what the score of a message that got through is, that'll tell you how close it was to being flagged as spam (spam threshold is usually about 12 or so, but they've all got their own systems). I suspect that the score for a clean message will be quite high, and adding the link is just the final straw.

The other thing to watch out for is that if you're generating the mail from a script, make sure that it's filling in all the appropriate headers, as missing ones will bump your spam score up by a fair bit. Logs from the SMTP conversation between the server sending the mail and whatever it's relaying to would also be helpful.

4

You need to make sure that your mail server (most likely the same machine as your php code is running from) is correctly configured to send mail legitimately. You need ensure of a few things are correct to avoid any mail being relayed from that machine being marked as spam off the bat.

Firstly, your mail server MUST say HELO with it's canonical host name, that is the same value as the hostname command returns when run on the command line. Under postfix this is the value of the myhostname variable in /etc/postfix/main.cf.

Secondly, the forward and reverse pointers for your server in DNS must match, and must match the hostname value above. For example

[dave@odessa ~]$ host odessa.cheney.net
odessa.cheney.net has address 64.85.168.249
[dave@odessa ~]$ host 64.85.168.249
249.168.85.64.in-addr.arpa domain name pointer odessa.cheney.net.

Thirdly, check that your mail server is not acting as a open relay. If your mail server is configured to relay mail from other hosts, you should be very careful to ensure that those hosts themselves are not open relays, or are properly protected from accepting messages from unauthenticated hosts There are plenty of sites out there that will make a check for you, http://www.checkor.com/ for example.

Fourthly, look at the content of your message. From the sample you posted above it looks like you are send a small piece of HTML, which will most likely set of alarms with spam filters (take a look at the composition of your average piece of spam). You should always use an email library to compose your mail, and if you send HTML mail, you should include a text/plain variant.

Lastly, with the large sites, some of our mail will marked as spam, it's just the law of averages. It's your responsibility to make sure you comply with the appropriate regulations for send automated or bulk email, like CAN-SPAM. The most important part of this is a straight forward way for people to unsubscribe from your mailing lists. If you make this hard for people then you're users are more likely to hit the large spam button in their mail client which will be fed back to the mail host and will work against your server.

1

Every email site will apply its own rules for spam detection. You will not find a perfect method for not being classified as spam. At a first glance, the ! in the subject and the content entirely in HTML are good indicators of spam...

Send an email to [email protected] and you will receive back an automatic report with an analysis of how it looks like and what its spamicity is. It can give you some ideas.

0

There is little you can do from code. While you can use something like DKIM, there's no guarantees that the recipients will use it. Personally, I would focus on making your email look less like fire-and-forget spam and more like something "official" that the user actually asked for. Could you edit your post to include an actual email that your system sent?

0

About 18 months ago we had problems getting our emails delivered to Yahoo addresses because the link contained a domain that was newly registered.

We identified this by checking the bounced emails. Yahoo itself was reporting "your email has been delayed" but a couple other mail servers gave a clue in their error message for refusing delivery. Changing the domain back to an older, more established domain fixed the problem.

Also consider the words in the link (e.g. saying something like DOWNLOAD FREE SOFTWARE NOW instead of Download software version 1.0) and the domain name in the link itself.

You must log in to answer this question.