Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complete mail header

Tags:

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 <[email protected]>' . "\r\n";   

Is there anything else I should add?

like image 957
johnnietheblack Avatar asked Feb 19 '09 16:02

johnnietheblack


People also ask

How do I get an entire email header?

Click the email you want to see the headers for so it shows in the window below your inbox. Right click the body of the email. Click View All Headers and Message.

What are the 7 important information of the header in an email?

Header Characteristics From: sender's name and email address (IP address here also, but hidden) To: recipient's name and email address. Date: sent date/time of the email. Subject: whatever text the sender entered in the Subject heading before sending.


2 Answers

    $headers  = "From: testsite <[email protected]>\n";     $headers .= "Cc: testsite <[email protected]>\n";      $headers .= "X-Sender: testsite <[email protected]>\n";     $headers .= 'X-Mailer: PHP/' . phpversion();     $headers .= "X-Priority: 1\n"; // Urgent message!     $headers .= "Return-Path: [email protected]\n"; // Return path for errors     $headers .= "MIME-Version: 1.0\r\n";     $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; 
like image 144
Rohit Dubey Avatar answered Sep 29 '22 11:09

Rohit Dubey


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.

like image 32
Joseph Tary Avatar answered Sep 29 '22 12:09

Joseph Tary