From Joomla! Documentation

Revision as of 13:51, 23 November 2008 by Chris Davenport (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Returns a reference to the global mail object, only creating it if it doesn't already exist. The object returned will be of type JMail.


object JMail getMailer()


In this example, a test email is sent to the email address of the site owner.

$mail =& JFactory::getMailer();
$config =& JFactory::getConfig();
$mail->addRecipient( $config->getValue( 'config.mailfrom' ) );
$mail->setSubject( 'Test message' );
$mail->setBody( 'This is an example email to test the Joomla! JFactory::getMailer() method.  Please ignore it' );
if ($mail->Send()) {
  echo "Mail sent successfully.";
} else {
  echo "An error occurred.  Mail was not sent.";

See also