41

I am using mailto link to populate bcc of users default email program.

$mem_email=" ";    
$sql="SELECT email_address FROM employee";
$contacts = $db->query($sql);
while($contact = $db->fetchByAssoc($contacts))
{
    if($contact['email_address']!="" && $contact['email_address']!=NULL)
    {
        $mem_email.=$contact['email_address'].", ";
    }
}

header("Location: mailto:?bcc={$mem_email}"); 

What is the best separator to separate multiple emails in bcc field: , or ; ?

In my case, I am using ,.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Mansoor Jafar
  • 1,458
  • 3
  • 15
  • 31

4 Answers4

51

The separator should be a comma (,) and there should not be a space.

See RFC 6068.

Alnitak
  • 334,560
  • 70
  • 407
  • 495
16

Here's a late caveat in case anybody needs it:

Even though RFC explicitly recommends a comma, Microsoft Outlook will use the "list separator character" defined in the regional settings. Your mailto links may not work correctly for your Windows + Outlook users whose systems are configured with a different list separator such as semicolons. Outlook will simply refuse to split the e-mail addresses with commas.

Just something to keep in mind.

Ishmaeel
  • 14,138
  • 9
  • 71
  • 83
  • Well, I seem to have a counterexample to this. I have Windows 10 and Outlook 365, and my regional settings clearly specify comma as List Separator. In fact it doesn't allow me to change it to anything else, at least not under my setting of U.S. English. But Outlook absolutely requires a semicolon separating recipients. In fact when I type a recipient, it automatically inserts a semicolon and space after every one (even the last one on the line). I can edit out the space and it still works, but if I go to the Outbox and look at the mail, the space has been reinserted by Outlook. – phantomflash May 11 '23 at 02:17
  • OK, a modification to the above comment. Upon further investigation, I have discovered an option in Outlook. (In my version,) you can click File - Options - Mail, scroll down to the Send Messages section, and check "Commas can be used to separate multiple message recipients". If this is checked, Outlook actually takes the commas, and after about 3 seconds (as it validates the given Email addresses against its own address book) actually changes them to semicolons. So now people can argue over who should work harder to adapt: the developer creating the mail program, or the Outlook user. – phantomflash May 11 '23 at 03:00
  • @phantomflash, good to know that they somewhat improved the behavior in under ten years. – Ishmaeel May 11 '23 at 05:05
  • Since my comments, I have read one source saying this feature was introduced in Outlook 2010. – phantomflash May 12 '23 at 23:41
3

TLDR Solution

TLDR Answer: Use a , without spaces to separate e-mail addresses.

RFC6068: The 'mailto' URI Scheme (published October, 2010) is only a proposed standard, and it is not an accepted, Internet standard. It also doesn't discuss comma-separation.

TLDR Caveats/Gotchya's

  • Be aware (per RFC6854) that you shouldn't comma-separate addresses in an e-mail's Sender field (for security reasons).
  • Many services allow spaces with the ,, so an ideal regex for splitting would be /\s*,\s*/.
  • Outlook and Exchange (and other X.400/X.500-compliant software) supports using a ;. This is because the X.400/X.500 specification that treats semicolons as a valid name-separator (see RFC1485, published July, 1993). Going forward, using , is recommended.

The Source

To quote the original proposed standard, RFC2822: Internet Message Format, published April, 2001...

3.6.3. Destination address fields

The destination fields of a message consist of three possible fields, each of the same form: The field name, which is either "To", "Cc", or "Bcc", followed by a comma-separated list of one or more addresses (either mailbox or group syntax).

to              =   "To:" address-list CRLF

cc              =   "Cc:" address-list CRLF

bcc             =   "Bcc:" [address-list / CFWS] CRLF

This proposed standard was accepted as a draft standard in October, 2008, with RFC5322: Internet Message Format. I would quote the text there, but they decided to keep it exactly as it is. An update was proposed in March, 2013, with RFC6854: Update to Internet Message Format to Allow Group Syntax...: you shouldn't be allowing comma-separated values in the Sender field, because then it's uncertain who really triggered sending the e-mail. To quote this RFC, RFC6854...

2.1. Replacement of RFC 5322, Section 3.6.2. Originator Fields

...The from field and the sender field SHOULD NOT use group syntax; rather, the from field SHOULD use only the mailbox-list syntax and the sender field SHOULD use only mailbox syntax (see RFC 6854, Section 3). If the sender field uses group syntax, the group MUST NOT contain more than one mailbox.

Community
  • 1
  • 1
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
1

Use following code,

implode(',', $contacts);

above code will give comma separated emails.

Amar Gharat
  • 134
  • 3
  • I have used `$mem_email.=$contact['email_address'].", ";` and it is doing well , – Mansoor Jafar Aug 25 '12 at 08:56
  • I used `$mem_email.=$contact['email_address'].",";` and it's doing well . Is `implode(',', $contacts);` has any additional benefit ?? – Mansoor Jafar Aug 25 '12 at 08:58
  • mansoor, with your version, your concatenated email address string will have a trailing comma, but using implode will just put a comma between the addresses, not at the end. Aside from that, it's purely aesthetic - simpler code looks nicer and is easier to follow, but ultimately it's up to you -- the tiny differences in optimisation won't make any difference in this instance. – Ben Green Sep 21 '17 at 10:51
  • following on from my last comment, implode won't check for empty or null values in the array, so you would need to array_filter() before imploding, if you were to do it that way. – Ben Green Sep 21 '17 at 10:54