I get the messages "Test mail could not be sent." when I use the 'Send Test Email' button in Joomla 4.2.1 - on two sites. I have checked the SMTP settings and all OK. I know that the server will send emails as set up because the Contact forms work fine. But according to that message the settings are wrong!

Any suggestions about how to fix that? I have run Reinstall Joomla! core files with no improvement.

1 Answer 1


It is difficult to give you an exact answer without any more details or being able to debug your processing but looking at the code that is running I might be able to give you somewhere to look.

If you switch Error Reporting to Maximum in Global Config, third tab across, and Debug System to Yes, second tab, you might get more useful messages that narrow down where the problem is occurring. You may need to turn Gzip off also. enter image description here enter image description here

The error message you are receiving is coming from administrator/components/com_config/src/Model/ApplicationModel.php in the last function, sendTestMail() on the second last line. I suspect that the line $mailSent = $mailer->send(); is returning something other than true

    public function sendTestMail()
    // Set the new values to test with the current settings
    $app = Factory::getApplication();
    $user = Factory::getUser();
    $input = $app->input->json;
    $smtppass = $input->get('smtppass', null, 'RAW');

    $app->set('smtpauth', $input->get('smtpauth'));
    $app->set('smtpuser', $input->get('smtpuser', '', 'STRING'));
    $app->set('smtphost', $input->get('smtphost'));
    $app->set('smtpsecure', $input->get('smtpsecure'));
    $app->set('smtpport', $input->get('smtpport'));
    $app->set('mailfrom', $input->get('mailfrom', '', 'STRING'));
    $app->set('fromname', $input->get('fromname', '', 'STRING'));
    $app->set('mailer', $input->get('mailer'));
    $app->set('mailonline', $input->get('mailonline'));

    // Use smtppass only if it was submitted
    if ($smtppass !== null)
        $app->set('smtppass', $smtppass);

    $mail = Factory::getMailer();

    // Prepare email and try to send it
    $mailer = new MailTemplate('com_config.test_mail', $user->getParam('language', $app->get('language')), $mail);
            'sitename' => $app->get('sitename'),
            'method' => Text::_('COM_CONFIG_SENDMAIL_METHOD_' . strtoupper($mail->Mailer))
    $mailer->addRecipient($app->get('mailfrom'), $app->get('fromname'));

          $mailSent = $mailer->send();
    catch (MailDisabledException | phpMailerException $e)
         .... This bit of code isn't running so I don't think it is
              causing an exception 


    if ($mailSent === true)
     .... This code only runs if your mail was successful.

    $app->enqueueMessage(Text::_('COM_CONFIG_SENDMAIL_ERROR'), 'error');

    return false;
  • Thanks - I will track that through - at least starting point
    – NickOg
    Sep 8, 2022 at 4:02
  • Hmmm! I have tried adding code like var_dump($mail); but no output - no error message. I clearly don't understand models. :) But since the same code works on other sub domains is it reasonable to assume the problem is in some db record?? And if so where?? Nick
    – NickOg
    Sep 10, 2022 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.