$mailer = JFactory::getMailer(); $mailer->setSender('info@example.com'); $mailer->addRecipient('user@example.com'); $mailer->setSubject('Hello from my website'); $mailer->setBody('This is a test email message'); $mailer->IsHTML(true); $sent = $mailer->send();
$mailer = JFactory::getMailer(); $config = JFactory::getConfig(); $mailfrom = $config->get('mailfrom'); $fromname = $config->get('fromname'); $mailer->setSender(array($mailfrom, $fromname)); $mailer->addRecipient('user@example.com'); $mailer->setSubject('Hello from my website'); $mailer->setBody('This is a test email message'); $mailer->IsHTML(true); $sent = $mailer->send();In this example, we create a new instance of the JMail class using the getMailer method from the JFactory class. We then use the JFactory getConfig method to fetch the mailfrom and fromname settings from the configuration file, and use those as the sender of the email message. We set the recipient, subject, and body of the message as before, and call the send method to send the message. The package library for these examples is the Joomla framework, which is a popular open-source content management system (CMS) written in PHP. The JFactory class is a fundamental class within the Joomla framework which provides access to many other important classes and functions. The JMail class is a library class specifically for sending email messages.