When a legacy hook_mail() implementation sets $message['plain'] to a render Markup object (a rendered plain-text body, as easy_email does), the mailer_override legacy bridge throws a TypeError.

LegacyMailerHelper::emailFromArray() passes $message['plain'] straight to BaseEmail::setTextBody(), which is typed string:

TypeError: Drupal\symfony_mailer\BaseEmail::setTextBody(): Argument #1 ($body) must be of type string, Drupal\Core\Render\Markup given, called in LegacyMailerHelper.php on line 153.

The HTML body path already handles MarkupInterface in formatBody(); only the plain-text path is missing the conversion. Core PhpMail stringified the body implicitly, so legacy senders that supplied Markup worked before mailer_override.

Steps to reproduce:
1. Install symfony_mailer with the mailer_override submodule.
2. Send via the legacy mail manager with $message['plain'] set to Markup::create('some text').
3. The send fails with the TypeError above.

Proposed fix: cast to string at LegacyMailerHelper.php line 153, matching what core did implicitly:
$email->setTextBody((string) $message['plain']);

Happy to provide a merge request with a test.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review
adamps’s picture

Thanks

adamps’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • adamps committed 20f2e01e on 2.x authored by mably
    Issue #3594017: Accept a Markup plain-text body in LegacyMailerHelper
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.