Headers php mail server
Here are some common headers that can be used in a PHP mail script to configure the mail server and improve deliverability:
From Header
From
: specifies the sender's email address and name.- Example:
From: "John Doe" <[email protected]>
To Header
To
: specifies the recipient's email address.- Example:
To: [email protected]
Subject Header
Subject
: specifies the subject of the email.- Example:
Subject: Test Email
Reply-To Header
Reply-To
: specifies the email address that should receive replies to the email.- Example:
Reply-To: [email protected]
CC Header
CC
: specifies the email addresses that should receive a copy of the email.- Example:
CC: [email protected], [email protected]
BCC Header
BCC
: specifies the email addresses that should receive a blind carbon copy of the email.- Example:
BCC: [email protected], [email protected]
MIME Header
MIME-Version
: specifies the version of the MIME standard used in the email.- Example:
MIME-Version: 1.0
Content-Type
: specifies the type of content in the email (e.g. text/plain, text/html, etc.).- Example:
Content-Type: text/plain; charset=UTF-8
Authentication Header
Authentication-Results
: specifies the authentication results for the email.- Example:
Authentication-Results: spf=pass (sender IP is 192.0.2.1) smtp.mailfrom=example.com
DKIM-Signature
: specifies the DKIM signature for the email.- Example:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=From:To:Subject:Date:Message-ID; bh=...; b=...
Other Headers
Date
: specifies the date and time the email was sent.- Example:
Date: Wed, 12 Jan 2022 14:30:00 +0000
Message-ID
: specifies a unique identifier for the email.- Example:
Message-ID: <[email protected]>
X-Mailer
: specifies the email client or script that sent the email.- Example:
X-Mailer: PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)
X-Priority
: specifies the priority of the email (e.g. high, normal, low).- Example:
X-Priority: 3
Here is an example of a PHP mail script that uses some of these headers:
<?php
$headers = array(
'From' => 'John Doe <[email protected]>',
'To' => '[email protected]',
'Subject' => 'Test Email',
'Reply-To' => '[email protected]',
'MIME-Version' => '1.0',
'Content-Type' => 'text/plain; charset=UTF-8',
'Authentication-Results' => 'spf=pass (sender IP is 192.0.2.1) smtp.mailfrom=example.com',
'DKIM-Signature' => 'v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=From:To:Subject:Date:Message-ID; bh=...; b=...',
'Date' => date('r'),
'Message-ID' => '<'. uniqid(). '@example.com>',
'X-Mailer' => 'PHPMailer 6.0.5 (https://github.com/PHPMailer/PHPMailer)',
'X-Priority' => '3'
);
$mail = mail('[email protected]', 'Test Email', 'This is a test email.', $headers);
if ($mail) {
echo 'Email sent successfully!';
} else {
echo 'Error sending email!';
}
?>
Note that the specific headers and values used may vary depending on your email server and the requirements of your email recipients.