[tips] 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->setSender($sender); $mailer->addRecipient($recipient); $mailer->isHtml($is_html); $mailer->CharSet = 'UTF-8'; $mailer->Encoding = 'base64'; $mailer->setSubject($subject); $mailer->setBody($body); $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!