TIPS - How to send an email in text and html using Joomla! 3 JMail api?

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

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!

Alexandre ELISÉ

Développeur #PHP spécialiste #Joomla! Si mon travail vous a plu n'hésitez pas à laisser votre avis sur Google Reviews. Si mes articles vous ont été utiles vous pouvez me le dire avec ça m'encourage à continuer et me permet de savoir que vous apprecier le contenu. Sinon vous pouvez toujours m'envoyer un email pour me faire part de vos suggestions.

Get the newsletter

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.