Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format an email 'From' header that contains a comma

The standard way to format the 'From' email header is

From: John Doe <[email protected]> 

But what to do if there's a comma in the name?

From: John Doe, chief bottle washer <[email protected]> 

If I do that, my MTA automatically converts this into:

From: [email protected], [email protected], chief bottle washer <[email protected]> 

My first guess is to use double-quotes around the full name, but I can't find any official documentation confirming this and I'd like my emails to be readable by all email clients.

like image 426
Dalin Avatar asked Mar 21 '13 18:03

Dalin


People also ask

Can you have a comma in an email address?

A common usage is for defining sub-addresses. Example: The user 'joe' with the mail address '[email protected]' can set up mail addresses like '[email protected]' if he needs more then one address. The comma is used in address header fields to separate email addresses from each other.

What sections of the email header have to be filled in?

In an email, the body (content text) is always preceded by header lines that identify routing information of the message, including the sender, recipient, date and subject. Some headers are mandatory, such as the From, To, and Date headers. Others are optional, but very commonly used, such as Subject and CC.

What are the four parts of an email header?

An email header is the area in which you enter important information above the email content area. The information in the header includes such things as the recipient, the sender, and a subject line with the option of sending copies to additional recipients.

What does a full email header look like?

An email header tells who sent the email and where it arrived. Some markers indicate this information, like “From:” — sender's name and email address, “To:” — the recipient's name and email address, and “Date:” — the time and date of when the email was sent. All of these are mandatory indicators.


2 Answers

To elaborate on the answer by @Fls'Zen, yes the proper method is to enclose the name in double-quotes.

From a practical point of view there's no harm in wrapping all names in double-quotes, just be sure to escape a double-quote if it appears in the display name \" (or just replace with a single-quote). But if you want to be completely by the spec, you shouldn't use the double quotes if you don't have to.

For all the dense details, E-mail header fields are defined by RFC 5322. The relevant section for multiple originators in the From header is 3.6.2, and the relevant sections for quoting delimiters is 3.2.1 and 3.2.4.

like image 107
Dalin Avatar answered Sep 18 '22 19:09

Dalin


When the following regular expression matches, then an email display address must be quoted.

[^-A-Za-z0-9!#$%&'*+/=?^_`{|}~\s] 

For ASCII characters, this can be done by escaping any double quote characters with a backslash, and enclosing the string in double quotes. For non-ASCII characters, the more complex MIME escaping is required.

like image 43
Diomidis Spinellis Avatar answered Sep 18 '22 19:09

Diomidis Spinellis