You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[Mime] Fix undefined array key 0 when empty sender
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | N/A
| License | MIT
Today I managed to produce the following error :

From the following code :
```php
$email = (new TemplatedEmail())
->from()
->to($member->getEmail())
->subject('Adhésion Sauvade')
->htmlTemplate('emails/new-membership/index.html.twig')
->context([
'member' => $member,
])
->addPart(new DataPart(
$this->pdfService->generatePdfFromTemplate(
'emails/new-membership/attachments/recu.html.twig',
['member' => $member]
),
))
->addPart(new DataPart(
$this->pdfService->generatePdfFromTemplate(
'emails/new-membership/attachments/membership-card.html.twig',
['member' => $member]
),
))
;
$this->mailer->send($email);
```
This happens because the `from` method from the `Symfony\Component\Mime\Email` class adds the header even if the array of addresses is empty. I identified two ways of fixing this :
- Adding a check in the `Symfony\Component\Mime\Message` class before accessing the key 0 and throw a better exception in case the adresses are empty
- Modifying the `from` method so that it doesn't add the header if the adresses are empty; or throw an exception when trying to do so.
I'm unsure what method is the cleaner, I thought that fixing the Message access of an undefined key was the widest fix (as I guess it could happen from somewhere else than the Mailer component). Also not sure how to test that and wanted to make sure this fix was good before testing it.
Commits
-------
ee49a78 [Mime] Fix undefined array key 0 when empty sender
0 commit comments