Joomla content management system allows users to send emails from Joomla extensions. You can take advantage of this feature and send emails to anyone you wish, right from the Joomla extensions. This blog post will help you how to send emails from Joomla extensions in easy steps.
Key components of an email include the sender, recipient, and the message body. To send emails from Joomla extensions, you need to follow the below steps:
$config =JFactory::getConfig(); $sender = array( $config->getValue( 'config.mailfrom' ), $config->getValue( 'config.fromname' ) ); $mailer->setSender($sender);
$user = JFactory::getUser(); $recipient = $user->email; $mailer->addRecipient($recipient);
1. Plain Text Mail
$body = "Your body stringnin double quotes if you want to parse the nnewlines etc"; $mailer->setSubject('Your subject string'); $mailer->setBody($body); // Optional file attached $mailer->addAttachment(JPATH_COMPONENT.DS.'assets'.DS.'document.pdf');
2. HTML Format Mail
$body = '<h2>Our mail</h2>' . '<div>A message to our dear readers' . '<img src="cid:logo_id" alt="logo"/></div>'; $mailer->isHTML(true); $mailer->Encoding = 'base64'; $mailer->setBody($body); // Optionally add embedded image $mailer->AddEmbeddedImage( JPATH_COMPONENT.DS.'assets'.DS.'logo128.jpg', 'logo_id', 'logo.jpg', 'base64', 'image/jpeg' );
$send = $mailer->Send(); if ( $send !== true ) { echo 'Error sending email: ' . $send->message; } else { echo 'Mail sent'; }
If you encounter difficulties sending emails successfully or receive an error message, you can Request a Quote from our Joomla team of experts. We also develop custom Joomla extensions, including those designed to make sending emails easier. Visit our Joomla store for more useful extensions for your website. Follow the steps outlined above carefully to send emails from Joomla extensions.