Malcolm Lyon
Malcolm Lyon

Reputation: 13

What should Factory::getMailer() be replaced with in Joomla 5?

I have several custom Joomla components which use Factory::getMailer() to send emails, but I notice that this method is deprecated and will be unavailable in Joomla 6. I haven't been able to find any simple instructions for how to replace Factory::getMailer() in Joomla 4+.

I have tried using Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer() but this throws an error because it seems like I probably have to set up some stuff in the provider.php file and/or the component file. I can't find any information about exactly what is required.

Upvotes: 1

Views: 118

Answers (1)

Jumbo
Jumbo

Reputation: 521

You can use -

$config = \Joomla\CMS\Factory::getApplication()->getConfig();
$mailer = \Joomla\CMS\Factory::getContainer()->get(\Joomla\CMS\Mail\MailerFactoryInterface::class)->createMailer($config);

Upvotes: 0

Related Questions