Undefined array key "swiftmailer"

Created on 7 July 2023, over 1 year ago
Updated 3 April 2024, 8 months ago

Problem/Motivation

I'm seeing warnings on every email send out. The warning is on line 81 and 171

Logs:

Warning: Undefined array key "swiftmailer" in Drupal\symfony_mailer\Plugin\EmailAdjuster\WrapAndConvertEmailAdjuster->build() (line 81 of /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Plugin/EmailAdjuster/WrapAndConvertEmailAdjuster.php)
#0 /srv/shared/builds/sitename/htdocs/core/includes/bootstrap.inc(347): _drupal_error_handler_real()
#1 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Plugin/EmailAdjuster/WrapAndConvertEmailAdjuster.php(81): _drupal_error_handler()
#2 [internal function]: Drupal\symfony_mailer\Plugin\EmailAdjuster\WrapAndConvertEmailAdjuster->build()
#3 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Email.php(490): call_user_func()
#4 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Mailer.php(180): Drupal\symfony_mailer\Email->process()
#5 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Mailer.php(150): Drupal\symfony_mailer\Mailer->doSend()
#6 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\symfony_mailer\Mailer->Drupal\symfony_mailer\{closure}()
#7 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Mailer.php(159): Drupal\Core\Render\Renderer->executeInRenderContext()
#8 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Email.php(292): Drupal\symfony_mailer\Mailer->send()
#9 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/EmailFactory.php(46): Drupal\symfony_mailer\Email->send()
#10 /srv/shared/builds/sitename/htdocs/modules/contrib/symfony_mailer/src/Form/TestEmailForm.php(90): Drupal\symfony_mailer\EmailFactory->sendTypedEmail()
#11 [internal function]: Drupal\symfony_mailer\Form\TestEmailForm->submitForm()
#12 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Form/FormSubmitter.php(114): call_user_func_array()
#13 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Form/FormSubmitter.php(52): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
#14 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm()
#15 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Form/FormBuilder.php(325): Drupal\Core\Form\FormBuilder->processForm()
#16 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
#17 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
#18 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#19 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#20 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#21 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#22 /srv/shared/builds/sitename/vendor/symfony/http-kernel/HttpKernel.php(169): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#23 /srv/shared/builds/sitename/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#24 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle()
#25 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#26 /srv/shared/builds/sitename/htdocs/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#27 /srv/shared/builds/sitename/htdocs/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
#28 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#29 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#30 /srv/shared/builds/sitename/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#31 /srv/shared/builds/sitename/htdocs/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
#32 /srv/shared/builds/sitename/htdocs/index.php(19): Drupal\Core\DrupalKernel->handle()
#33 {main}

Steps to reproduce

Send a test email and inspect the logs.

Proposed resolution

Perhaps only an isset() check has to be added?

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇳🇱Netherlands Johan den Hollander

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

Comments & Activities

  • Issue created by @Johan den Hollander
  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • @sakthi_dev opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India sakthi_dev

    Please review.

  • Status changed to Needs work over 1 year ago
  • 🇳🇱Netherlands Johan den Hollander

    Changing back because the warning is on line 81 and 171.
    The MR is not fixing both problems.

  • First commit to issue fork.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • Status changed to Needs review over 1 year ago
  • 🇨🇴Colombia metallized

    Please review

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India keshavv India

    Reviewed the #6 MR and confirms that it will fix the above warning.

  • 🇳🇱Netherlands Johan den Hollander

    Confirming that the added checks remove the warning while emails are still being send out.

  • Status changed to Postponed: needs info over 1 year ago
  • 🇬🇧United Kingdom adamps

    I don't see how to hit this issue. When you save Mailer Policy configuration containing WrapAndConvertEmailAdjuster then it will set $this->configuration['swiftmailer']. Please try it - save your policy again and the problem should be fixed.

    Please can give steps to reproduce.

  • Status changed to RTBC 9 months ago
  • 🇨🇦Canada RobLoach Earth

    While I understand re-saving the configuration can fix this, one should likely not depend on $this->configuration['swiftmailer'] always being there. With the config not there, this code would be fine in PHP <= 5, but PHP is a bit more strict nowadays. I'd recommend bringing this change in because it will save many other cases where this issue occurs.

  • 🇨🇦Canada RobLoach Earth

    Found another PHP strict issue. Here's a patch for plain too...

  • Status changed to Postponed: needs info 9 months ago
  • 🇬🇧United Kingdom adamps

    > one should likely not depend on $this->configuration['swiftmailer'] always being there.

    But why not? I don't see how it can be missing in correct usage. As it says in #10, please can give steps to reproduce. That's the information needed before changing the status please.

  • 🇺🇸United States ExTexan

    I agree with @RobLoach. The condition IS being encountered, so it's better to fix it, even if you can't imagine how it is possible.

    In my case, I upgraded a site that was on D8.9, through D9.5, to D10. In doing so, I started with the D8.9 database (cloned from the live site), and ran a massive (1200+ entry) config sync on it. In the D8 site, I was using SwiftMailer, but uninstalled it during the updates of Drupal core, contrib and custom modules, during the move to D10. Somewhere in all that syncing, the configuration for symphony_mailer ended up in such a state as to trigger this error.

    So, by performing normal steps to upgrade Drupal and contrib modules, this condition was created. Please tell me how I could have done it differently to avoid the error?

  • 🇨🇦Canada bbombachini London, ON

    If it helps I have this issue on a site I have installed from scratch which I have copied over the config from another site that I have migrated from switfmailer to symfony_mailer.
    Now, I tried to re-save the config, I've removed manually and re-imported, and I still get this error.

    Hope this helps.

Production build 0.71.5 2024