Headers php mail format

Here are the common headers used in PHP mail format:

Required Headers

  1. From: specifies the sender's email address and name.
  2. To: specifies the recipient's email address.
  3. Subject: specifies the subject of the email.
    • Format: Subject: This is the subject of the email

Optional Headers

  1. Reply-To: specifies the email address to which the recipient should reply.
  2. CC: specifies the email addresses to which a carbon copy of the email should be sent.
  3. BCC: specifies the email addresses to which a blind carbon copy of the email should be sent.
  4. MIME-Version: specifies the version of the MIME (Multipurpose Internet Mail Extensions) standard used in the email.
    • Format: MIME-Version: 1.0
  5. Content-Type: specifies the format of the email body.
    • Format: Content-Type: text/plain; charset=UTF-8 (for plain text emails) or Content-Type: text/html; charset=UTF-8 (for HTML emails)
  6. Content-Transfer-Encoding: specifies how the email body is encoded.
    • Format: Content-Transfer-Encoding: 7bit (for plain text emails) or Content-Transfer-Encoding: base64 (for binary attachments)
  7. Date: specifies the date and time the email was sent.
    • Format: Date: Mon, 01 Jan 2023 12:00:00 +0000

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.