Complete mail header

0 votes
asked Feb 19, 2009 by johnnietheblack

I need a set of mail headers to attach to my mail() function in PHP. I send emails with HTML in them, and sometimes services like Yahoo Mail 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 <welcome@mycompany.com>' . "\r\n";  

Is there anything else I should add?

7 Answers

0 votes
answered Jan 19, 2009 by jasper

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 automail@mydomainnaim.com and adding a reply-to, being the person who sent the mail using my system.

0 votes
answered Jan 19, 2009 by joseph-tary

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.

0 votes
answered Jan 19, 2009 by hypercas

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

For example, http://phpmailer.codeworxtech.com/.

0 votes
answered Jan 5, 2013 by james-garriss

The RFCs for both IMF and MIME define the minimal set of headers, so this would be a good place to start.

For IMF, look here: http://tools.ietf.org/html/rfc5322#section-3.6

For MIME, look here: http://tools.ietf.org/html/rfc2045#section-3

0 votes
answered Jan 18, 2013 by malachi

The link below could be of some use defining the mandatory headers as:

  • Date: The date the message was originated/written.

  • From: The person "responsible" for the message.

http://www.by-users.co.uk/faqs/email/headers/#MandatoryMail

0 votes
answered Feb 18, 2013 by rohit-dubey
    $headers  = "From: testsite < mail@testsite.com >\n";
    $headers .= "Cc: testsite < mail@testsite.com >\n"; 
    $headers .= "X-Sender: testsite < mail@testsite.com >\n";
    $headers .= 'X-Mailer: PHP/' . phpversion();
    $headers .= "X-Priority: 1\n"; // Urgent message!
    $headers .= "Return-Path: mail@testsite.com\n"; // Return path for errors
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
0 votes
answered Jan 29, 2016 by gilson-gilbert

Please use the following list of headers with PHP's mail():

$headers  = "From: testsite < mail@domain.com >\n";
$headers .= "Cc: testsite < mail@domain.com >\n";
$headers .= "X-Sender: testsite < mail@domain.com >\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: mail@domain.com\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...