Argument #2 ($value) must be of type string, null given

Created on 30 October 2023, 8 months ago
Updated 9 December 2023, 7 months ago

Problem/Motivation

Error:

TypeError: Symfony\Component\Mime\Header\Headers::addTextHeader(): Argument #2 ($value) must be of type string, null given, called in /var/www/html/vendor/symfony/mime/Header/Headers.php on line 152 in Symfony\Component\Mime\Header\Headers->addTextHeader() (line 122 of /var/www/html/vendor/symfony/mime/Header/Headers.php).

When sends a message with Bcc, and without to, on the version 2.2.x it fills the to with a string.
https://git.drupalcode.org/project/reroute_email/-/blob/c61b4e654687d902...

  $mailkey = $message['id'] ?? t('[mail id] is missing');
  $to = $message['to'] ?? t('[to] is missing');

But on the version 2.3.x it expected a string, and never a NULL.
https://git.drupalcode.org/project/reroute_email/-/blob/a45e1158adf0e868...

  /**
   * {@inheritdoc}
   */
  public function getAddressTo() {
    if (array_key_exists("to", $this->configuration["email"])) {
      return $this->configuration["email"]["to"];
    }
    return NULL;
  }

On the method getAddressTo, returns NULL, because Symfony mailer set it the to, to NULL, see issue https://www.drupal.org/project/symfony_mailer/issues/3281130 β†’

But, the method setHeader expects a string.
https://git.drupalcode.org/project/reroute_email/-/blob/a45e1158adf0e868...

    $this->setHeader(RerouteEmailHandlerPluginInterface::HEADER_ORIGINAL_TO, $this->getAddressTo());

https://git.drupalcode.org/project/reroute_email/-/blob/a45e1158adf0e868...

  /**
   * Set email header.
   */
  public function setHeader(string $name, string $value): void;

Steps to reproduce

$to = '';
$params['Bcc'] = 'test@example.com,test2@example.com';
.
.
.
$mailManager = \Drupal::service('plugin.manager.mail');
$mail= $mailManager->mail($module, $key, $to, $langcode, $params, $reply, $send);

Proposed resolution

When the to is NULL, add a string as it was on the previous module version.

πŸ› Bug report
Status

Fixed

Version

2.3

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024