tags:

views:

1090

answers:

5

I need a set of mail headers to attach to my mail() function in PHP.

I send emails with HTML in them, and sometimes clients like Yahoo block them. Therefore I need to make sure that I am at least providing the right headers.

My code:

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: MyCompany <[email protected]>' . "\r\n";

Is there anything else I should add?

+1  A: 

If you're worried about HTML messages being blocked, then you should probably be sending multi-part MIME messages. Here's one way.

gms8994
awesome resource! just cuz im the new guy in school...could you help me understand what a multipart MIME message is? thanks for your patience:)
johnnietheblack
Multipart mime basically sends the HTML portion *and* a text-based version in the same message.
gms8994
+1  A: 

Did the mail really come from 'mycompany.com'? I've had problems with some mail services blocking if it didn't really come from the smtp server that the mail says it does.

A way around this, for me, was making the from to be [email protected] and adding a reply-to, being the person who sent the mail using my system.

Jasper
nah, that was just the header template i was using...i replaced the values:)
johnnietheblack
So the script / mailserver is the same as the domain you use in the 'from' ?
Jasper
+2  A: 

Most MUA's insert a lot of extra headers; however, here is sort of the bare minimum you can expect.

To: 
Subject:
Date: 
MIME-Version:
Content-type:

If you using HTML, then you should probably be using multipart messages--but it's not strictly necessary.

Joseph Tary
+1  A: 

When defining if a sender is a possible spammer, many services check if the domain of the sender looks like a dialup user.

Quote from Wikipedia:

One e-mail anti-spam technique: checking the domain names in the rDNS to see if they are likely from dialup users, dynamically assigned addresses, or other inexpensive internet services. Owners of such IP addresses typically assign them generic rDNS names such as "1-2-3-4-dynamic-ip.example.com." Since the vast majority, but by no means all, of e-mail that originates from these computers is spam, many spam filters refuse e-mail with such rDNS names.

Ólafur Waage
good to know..thanks mang
johnnietheblack
A: 

You can use a 3rd party class to do the work for you and would make a lot of other features available.

Eg: http://phpmailer.codeworxtech.com/

HyperCas