Headers php mail format
Here are the common headers used in PHP mail format:
Required Headers
From
: specifies the sender's email address and name.- Format:
From: "Your Name" <[email protected]>
- Format:
To
: specifies the recipient's email address.- Format:
To: [email protected]
- Format:
Subject
: specifies the subject of the email.- Format:
Subject: This is the subject of the email
- Format:
Optional Headers
Reply-To
: specifies the email address to which the recipient should reply.- Format:
Reply-To: [email protected]
- Format:
CC
: specifies the email addresses to which a carbon copy of the email should be sent.- Format:
CC: [email protected], [email protected]
- Format:
BCC
: specifies the email addresses to which a blind carbon copy of the email should be sent.- Format:
BCC: [email protected], [email protected]
- Format:
MIME-Version
: specifies the version of the MIME (Multipurpose Internet Mail Extensions) standard used in the email.- Format:
MIME-Version: 1.0
- Format:
Content-Type
: specifies the format of the email body.- Format:
Content-Type: text/plain; charset=UTF-8
(for plain text emails) orContent-Type: text/html; charset=UTF-8
(for HTML emails)
- Format:
Content-Transfer-Encoding
: specifies how the email body is encoded.- Format:
Content-Transfer-Encoding: 7bit
(for plain text emails) orContent-Transfer-Encoding: base64
(for binary attachments)
- Format:
Date
: specifies the date and time the email was sent.- Format:
Date: Mon, 01 Jan 2023 12:00:00 +0000
- Format:
Example PHP Mail Headers
$headers = array(
'From' => 'Your Name <[email protected]>',
'To' => '[email protected]',
'Subject' => 'This is the subject of the email',
'Reply-To' => '[email protected]',
'CC' => '[email protected], [email protected]',
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding' => '7bit',
'Date' => date('r')
);
Note that the Date
header is automatically set by PHP when you use the mail()
function.