Sending mails to multiple email addresses does not work

Created on 28 June 2023, almost 2 years ago
Updated 18 July 2023, almost 2 years ago

I'll create same issue that I've created on other symfony mailer module ( #3254085 β†’ )

Problem/Motivation

Sending multiple emails at once does not work as email validator throws exception Email "mail@test.com, mail2@test.com" does not comply with addr-spec of RFC 2822

Steps to reproduce

Send mail to multiple addresses separated by , (comma):

$mail_manager = \Drupal::service('plugin.manager.mail');
$mail_manager->mail('module', 'key', 'mail@test.com, mail2@test.com', 'en');

Proposed resolution

1. As direct successor to swiftmailer we can just reuse their swiftmailer_parse_mailboxes which will explode addresses, never seen anyone had problems with it.

\Drupal\swiftmailer\Utility\Conversion::swiftmailer_parse_mailboxes

2. Safest bet is to create hard dependency to PHP imap extension and use imap_rfc822_parse_adrlist. Downside is that we need to create probably unnecessary dependency.

3. Is to just use explode or str_getcsv which is not ideal because it does not cover all possibilities given as example in
\Drupal\Core\Mail\MailManagerInterface::mail interface comment.

4. It works if you pass emails as array.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡ΈSerbia holo96

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024