2

I am trying to send email of the format: 'Tom Smith, Jr <ts@example.com>'; 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?

2

Tom Smith, Jr <ts@example.com> and 'Tom Smith, Jr <ts@example.com>' are not valid email addresses, but "Tom Smith, Jr" <ts@example.com> 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.

2
  • Thanks but adding double quotes as I mentioned, doesn't work.
    – liquidcms
    Aug 11 at 13:39
  • 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.
    – liquidcms
    Aug 11 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.