Score:2

How to send email with commas in the name?

us flag

I am trying to send email of the format: 'Tom Smith, Jr <[email protected]>'; but it fails due to the comma in the name.

This closed issue: https://www.drupal.org/project/drupal/issues/2936032 dealt with handling commas in the site name for handling the From address. It basically added a helper function to wrap the name part in double quotes. But this doesn't work for the To address.

Any suggestions other than simply removing the comma?

Score:2
fr flag

Tom Smith, Jr <[email protected]> and 'Tom Smith, Jr <[email protected]>' are not valid email addresses, but "Tom Smith, Jr" <[email protected]> is. Drupal doesn't "fix" addresses to make them RFC 2047 compliant, you need to do that yourself or use a helper module (such as Mime Mail) which will take care of a lot of these little details for you. This is especially important if you want to use non-ASCII characters in your email addresses.

Drupal 8 core provides a \Drupal\Component\Utility\Mail::formatDisplayName() method you can use, but it is well-known to do the wrong thing in many cases and has been removed in Drupal 9.2. This is part of the reason the above-mentioned helper modules exist.

liquidcms avatar
us flag
Thanks but adding double quotes as I mentioned, doesn't work.
liquidcms avatar
us flag
Is it possible the failure comes from the mail server? I am using Papercut SMTP as a test mail server. There isn't much for error reporting; any issue is just returned as "can't send". It is hard to imagine that Drupal mail can't handle "last, first" as an email name.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.