Problem/Motivation
I am getting the following error when trying to send an email that has a bcc in the message header
$message['headers']['bcc'] = 'any@email.com'
The website encountered an unexpected error. Please try again later.
AssertionError: assert(isset($this->addresses[$name])) in assert() (line 58 of modules/contrib/symfony_mailer/src/BaseEmailTrait.php).
assert(, 'assert(isset($this->addresses[$name]))') (Line: 58)
Drupal\symfony_mailer\Email->setAddress('bcc', Array) (Line: 146)
Drupal\symfony_mailer\LegacyMailerHelper->emailFromArray(Object, Array) (Line: 136)
Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder->build(Object)
call_user_func(Array, Object) (Line: 490)
Drupal\symfony_mailer\Email->process() (Line: 180)
Drupal\symfony_mailer\Mailer->doSend(Object) (Line: 150)
Drupal\symfony_mailer\Mailer->Drupal\symfony_mailer\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 159)
Drupal\symfony_mailer\Mailer->send(Object) (Line: 292)
Drupal\symfony_mailer\Email->send() (Line: 92)
Steps to reproduce
using the legacy mailer try to send an email with a bcc header.
if I remove the bcc, the email sends.
The bcc is a valid email address.
Comments
Comment #2
loze commentedComment #3
adamps commentedThanks for the report. I believe it is confusion over the header case (as a workaround, probably 'Bcc' would work). Probably introduced by #3334230: Support all headers in LegacyEmailBuilder, where the different cases were starting to drive me crazy😃.
The simplest fix is to change
LegacyMailerHelper::emailFromArray()where the comment says "Convert to standard case.", make it like thisAnother option is to copy what Symfony library code does and store all headers in lower case internally. We need to be careful with legacy emails though as Drupal uses capitals.
Comment #4
loze commentedThank you. Changing it to
$message['headers']['Bcc'] = 'any@email.com'(capital B) got rid of the error.Comment #5
adamps commentedThanks for reporting back.
Comment #6
sokru commentedFaced the same issue when upgrading to Drupal 10. The tests will fail without the
$name = ucfirst($name))change.Comment #7
adamps commentedThanks for the patch. It's good and it works.
Two comments please:
if ($name == 'Reply-to')and we don't need to callucfirst().$name = strtolower($name)there too. Then fix all the string constants to lower case 'from' instead of 'From' etc.Comment #8
sokru commentedI hope I got all changes requested.
Comment #10
sokru commentedMissed a one thing on my previous patch.
Comment #11
adamps commentedGreat thanks.
You should put the strtolower before the assert.
Then you can put ToEmailAdjuster back as it was or also change the other 4 for consistency.
Comment #12
sokru commentedUpdated the all adjuster constants to lowercase.
Comment #14
adamps commentedGreat thanks