I recently had a conversation with an email guru concerning the ideal headers to use when sending plain-text email messages. Here is the punchline of that insightful exchange..
The best minimal set of headers to use when sending email:
I also like to add
X-Mailer:, but it’s not required.
Here is an example showing how these headers might be used when sending email via a PHP script:
$headers = 'X-Mailer: Simple Basic Contact Form'. "\n"; $headers .= 'From: '. $name .' <'. $email .'>'. "\n"; $headers .= 'Reply-To: '. $name .' <'. $email .'>'. "\n"; $headers .= 'Content-Type: text/plain; charset='. get_option('blog_charset', 'UTF-8') . "\n";
This snippet is written in the context of my free WordPress plugin, Simple Basic Contact Form, but the logic applies to any email that you want to send. Just change the WP stuff (i.e.,
get_option()) to whatever you’re working with.
Reply-To header is not technically required if it has the same value as the
From header. You don’t need both, but it’s fine to include both if desired. Totally up to you :)
Some related infos:
- You can have only one email address in a From header, so don’t do this:
From: Path Smith <firstname.lastname@example.org, email@example.com>
- If your Content-Type is plain, you shouldn’t be setting the MIME-Version header.
- Setting the Return-Path header is an RFC violation, don’t set it.
- Always set the Reply-To header of a contact form to be the visitor’s email address; that will enable the recipient to reply regardless of what shows up as the From address (e.g.,
Reply-To: [visitor-name] <[visitor-email]>