Sending a test email via PHPMailer throws an error if Database Logging module is disabled

Created on 7 December 2018, over 6 years ago
Updated 23 August 2024, 8 months ago

If the Database Logging module is disabled (for instance on a Production environment), an unexpected error page displays and when a test email is submitted from /admin/config/system/phpmailer.

The email does indeed send, but you don't get the usual "A test email has been sent" message, just an error.

We looked through our logs and saw the following:

Symfony\Component\Routing\Exception\RouteNotFoundException: Route "dblog.overview" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 201 of /mnt/www/html/project/docroot/core/lib/Drupal/Core/Routing/RouteProvider.php).

It appears that PHPMailer is hardcoding that route. After searching the module for dblog.overview, we found the following in /src/Form/SettingsForm.php:

264|  /**
265|   * {@inheritdoc}
266|   */
267|  public function submitForm(array &$form, FormStateInterface $form_state) {
268|    $values = $form_state->getValues();
...snip...
330|    /**
331|     * @todo This part needs to be figured out.
332|     */
333|    // Send a test email message, if an email address was entered.
334|    if ($values['phpmailer_test']) {
335|      // Since this is being sen to an email address that may not necessarily be
336|      // tied to a user account, use the site's default language.
337|      $langcode = $this->languageManager->getDefaultLanguage()->getId();
338|      // If PHPMailer is enabled, send via regular drupal_mail().
339|      if (phpmailer_active()) {
340|//        $this->mailManager->mail('phpmailer', 'test', $values['phpmailer_test'], $language_code, $params, $from, $send_now);
341|        \Drupal::service('plugin.manager.mail')->mail('phpmailer', 'test', $values['phpmailer_test'], $langcode);
342|      }
343|      // Otherwise, prepare and send the test mail manually.
344|      else {
345|        // Prepare the message without sending.
346|        $message = \Drupal::service('plugin.manager.mail')->mail('phpmailer', 'test', $values['phpmailer_test'], $langcode, [], NULL, FALSE);
347|        // Send the message.
348|        module_load_include('inc', 'phpmailer', 'includes/phpmailer.drupal');
349|        $ret_val = phpmailer_send($message);
350|      }
351|      $watchdog_url = Url::fromRoute('dblog.overview');
352|      $watchdog_url = \Drupal::l(t('Check the logs'), $watchdog_url);
353|      drupal_set_message(t('A test e-mail has been sent to %email. @watchdog-url for any error messages.', [
354|        '%email' => $values['phpmailer_test'],
355|        '@watchdog-url' => $watchdog_url,
356|      ]));
357|    }

Line 351 specifically tries to request the route to dblog.overview, regardless of whether or not the module is enabled which may be causing this issue.

Extra Info:
Using PHPMailer 8.x-3.0-beta2
Do you use Google Mail to send e-mails? No.

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Song

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024