Select your language

How to send an email in text and html using Joomla! 3 JMail api?
Photo from Unsplash

Hello super joomlers!

By default, you can only send and email in text only or html only with JMail api in Joomla! 3.

But with this code snippet, you can send both, html and text email at the same time.

This is useful to improve your score and find your email less and less in your customers spams mailbox.

Here is the code.

I stumbled upon this problem. Here is what worked for me:

    $mailer = JFactory::getMailer();
    $mailer->CharSet  = 'UTF-8';
    $mailer->Encoding = 'base64';
    $mailer->AltBody = $alt_body;
    $send = $mailer->Send();

The key point is here:

    $mailer->AltBody = 'Your text version of the email here';

This text message will be sent with the html counterpart and for users that do not wish to see the html version or cannot see it, they will see this text version.

Tested on Joomla 3.7.5
Hope it helps someone. Happy coding!

Super Joomlers! Get the most out of Joomla!
We hate spam as much as you do and we will not send you email without your prior consent. You can unsubscribe / resubscribe any time you want.