PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Helper / API Intermediate

Send Transactional Emails with MailerFactoryInterface in Joomla 5 and 6

Creates an isolated configured mailer (SMTP/Sendmail) via MailerFactoryInterface replacing deprecated Factory::getMailer().

Updated on 24 November 2026 59 copies 198 views
components/com_example/src/Helper/NotificationHelper.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;
use Joomla\CMS\Mail\MailerFactoryInterface;

$app    = Factory::getApplication();
$mailer = Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer();

$mailer->setSender([$app->get('mailfrom'), $app->get('fromname')]);
$mailer->addRecipient('');
$mailer->setSubject('Notificação do sistema');
$mailer->isHtml(true);
$mailer->setBody('<p>Operação concluída com sucesso.</p>');
$mailer->AltBody = 'Operação concluída com sucesso.';

$mailer->send();
Wrap $mailer->send() in try/catch because SMTP errors throw MailException in Joomla 5 and 6.
components/com_example/src/Helper/NotificationHelper.php
<?php
$config = JFactory::getConfig();
$mailer = JFactory::getMailer();
$mailer->setSender(array($config->get('mailfrom'), $config->get('fromname')));
$mailer->addRecipient('');
$mailer->setSubject('Notificação do sistema');
$mailer->setBody('Operação concluída.');
$mailer->Send();
Legacy Joomla 3 snippet calling JFactory::getMailer().

Technical explanation and best practices

In Joomla 5 and 6, replace deprecated Factory::getMailer() with MailerFactoryInterface::createMailer() so every message gets a clean, isolated PHPMailer instance.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.