Error: Call to a member function fromArray() on null in Drupal\symfony_mailer\MailManagerReplacement->mail()

Created on 8 August 2024, 4 months ago
Updated 15 August 2024, 3 months ago

Problem/Motivation

Getting below error when we have custom code written for mail(). for example:
$result = $mailManager->mail($module, $key, $to_list, $langcode, $params, NULL, $send);

Error: Call to a member function fromArray() on null in Drupal\symfony_mailer\MailManagerReplacement->mail() (line 89 of /var/www/web/modules/contrib/symfony_mailer/src/MailManagerReplacement.php).

๐Ÿ› Bug report
Status

Closed: duplicate

Version

1.4

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia omsingh89

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

Merge Requests

Comments & Activities

  • Issue created by @omsingh89
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Prem Suthar โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !98Add The not empty Condiiton For . โ†’ (Open) created by prem suthar
  • Status changed to Needs review 4 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    I think So you need to just add the not empty Condition on the $builder Variable So when $builder is empty then skip the call of this line
    $email = $builder->fromArray($this->emailFactory, $message);.

    For This I have added The Mr.

  • Pipeline finished with Failed
    4 months ago
    Total: 169s
    #247697
  • ๐Ÿ‡ต๐Ÿ‡นPortugal kallado

    @prem suthar your solution
    if (!$builder) {
    $email = $builder->fromArray($this->emailFactory, $message);
    }

    I haven't teste this but im pretty sure that if that condition is fulfiled (the $builder is NULL) you will have the same exact error.
    "Call to a member function fromArray() on null"
    This will also create another error in
    if ($send) {
    $message['result'] = $email->send();
    }
    Because the email won't be defined
    I think we have to digg a littlle bit deeper and understant why the $buildr is NULL in the first place

  • ๐Ÿ‡ต๐Ÿ‡นPortugal kallado

    Feals like in symfony_mailer/src/Processor/EmailBuilderManager.php
    /**
    * {@inheritdoc}
    */
    public function createInstanceFromMessage(array $message) {
    $this->buildCache();
    $suggestions = [
    "$message[module].$message[key]",
    $message['module'],
    ];

    foreach ($suggestions as $plugin_id) {
    if ($this->hasDefinition($plugin_id)) {
    return $this->createInstance($plugin_id);
    }
    if ($override_id = $this->overrideMapping[$plugin_id] ?? NULL) {
    return $this->createInstance($override_id);
    }
    }
    }

    There is nothing being returned and that is what causes the issue. It might not be a issue with the module but in the way you're handaling the email.

  • Status changed to Closed: duplicate 3 months ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom adamps

    I guess this is a duplicate of โœจ Handle case where hook_mail() does not exist Active

Production build 0.71.5 2024