Gerry Mckay
Gerry Mckay

Reputation: 847

mail() headers not preventing mail going to junk mail folders

im using these headers in my PHP to make sure that emails are avoiding the junk mail folder but they dont seem to be working very well.

 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
 $headers .= "From: [email protected] <[email protected]>\r\n"; 
 $headers .= "Reply-To: [email protected] <[email protected]>\r\n"; 
 $headers .= "Return-Path: [email protected] <[email protected]>\r\n";
 $headers .= "X-Priority: 3\r\n"; 
 $headers .= "X-MSMail-Priority: Normal\r\n"; 

is there anythin from the above code that u would change or remover that might help this work?

Upvotes: 0

Views: 4379

Answers (3)

Master Mind
Master Mind

Reputation: 1

$headers .= "Content-type: text/html; charset=utf-8\r\n";

will work on MSN or HOTMAIL

Upvotes: -1

SDC
SDC

Reputation: 14222

agreed with @MarcB: phpMailer is dead easy, and does all this stuff for you. Go here and download it. Then follow the examples here. You should be up and running in about ten minutes.

However, the really key point that should swing it for you is that you can tell phpMailer to send the mail via a different method to simply using PHP's mail() function.

Sending mail via your own PHP server is often the ultimate cause of the messages ending up being flagged as spam, because your PHP server is not recognised by the recieving mail systems as a legitimate source for email. So they assume it's spam. Systems like SPF and DomainKeys can be used to tell the world that your server is a legitimate server for email, but they can take time to learn and configure, and even more time for the message to get through to all the third party email servers out there.

With PHP's mail() function, you don't have a choice; the message is sent via your PHP server, and therefore unless you've got your domain configured very carefully, it can easily be flagged as spam.

But with phpMailer, it is possible to send via other routes, such as your main SMTP server, or even third party systems like gmail.

Sending via a recognised email server like this will very likely solve your problems, but it can only be done with phpMailer (or a similar class), not with PHP's built-in mail() function.

Again, all of this is dead easy to configure with phpMailer.

You can spend a week bashing your head against a wall, another week setting up SPF and DomainKeys, and another month or two waiting for Hotmail and friends to start recognising your PHP server as a legitimate email source.... or you can spend ten minutes learning phpMailer and other ten or twenty mins re-writing your code to use it, have it send the mail via a known legitimate mail server, and have your emails accepted immediately. Your choice.

Upvotes: 2

John Conde
John Conde

Reputation: 219804

Avoiding spam filters goes far beyond what headers you send with your emails. If your efforts stop with the code above you're going to find your level of success in avoiding spam filters to be so-so at best.

A few tips that you should keep in mind to help your mail avoid being marked as sapam:

  1. Set up DomainKeys for your domain

  2. Set up SPF for your domain

  3. Put an unsubscribe link in your email

  4. Set up Reverse PTR for your mail server's IP address

Upvotes: 1

Related Questions