- 🇨🇦Canada joelpittet Vancouver
Sorry for delayed response.
We are going to stay away from symfony_mailer for now. I feel it diverges too much from core's mailer it will likely have issue integrating with other modules that use core's API (even when using the "legacy" mode). It very much may be the future and be a brilliant idea, and I do hope it is realized and I'll come back to it periodically to see how things mature.
- Status changed to Active
about 1 year ago 1:02pm 25 October 2023 - 🇨🇦Canada lambic
I'm getting this error, but in the build phase not the pre-render phase:
TypeError: Unsupported operand types: null + array in Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder->build() (line 107 of modules/contrib/symfony_mailer/src/Plugin/EmailBuilder/LegacyEmailBuilder.php)
Here's the code we use to send the email:
$to = new Address($to, $toname, $language->getId()); $from = new Address($from, $fromname, $language->getId()); $htmlMessage = $payload->getMessage(); $converter = new Html2Text($htmlMessage, ['do_links' => 'table']); $textMessage = $converter->getText(); $result = $this->mailer2->newTypedEmail($module, $key) ->setTo($to) ->setFrom($from) ->setReplyTo($reply) ->setBody([ '#markup' => $htmlMessage, ]) ->setTextBody($textMessage) ->setSubject($payload->getSubject()) ->send();
- 🇨🇦Canada lambic
I got this working by changing the above code to:
$mail = $this->mailer2->newTypedEmail($module, $key, [ 'id' => $module, 'send' => TRUE, 'module' => $module, 'key' => $key, 'subject' => $payload->getSubject(), 'body' => [Markup::create($htmlMessage)], ]); $to = new Address($to, $toname, $language->getId()); $from = new Address($from, '"'.$fromname.'"', $language->getId()); $mail->setTo($to); $mail->setFrom($from); $mail->setReplyTo($reply); $mail->setTextBody($textMessage); $result = $mail->send();
but I'm noticing that the from and to headers are in lowercase, I think they're supposed to be 'From' and 'To'?
- 🇬🇧United Kingdom adamps
LegacyEmailBuilder is part of the implementation to handle emails sent using the old API. MailManagerInterface is an API, but LegacyEmailBuilder isn't. If you have code to use MailManagerInterface that became broken then I agree it could be an API change.
The code in #6 is using the new API. It's strange that LegacyEmailBuilder is called at all. Perhaps you also have a hook_mail implementation?? If so, that's the problem - you are mixing the old and new API.
I'm noticing that the from and to headers are in lowercase, I think they're supposed to be 'From' and 'To'?
I believe this comes from the Symfony\Component\Mime\Header\Headers class in symfony library (not this module).
- Status changed to Fixed
about 1 year ago 12:02pm 21 November 2023 Automatically closed - issue fixed for 2 weeks with no activity.