Sending email from extensions

From Joomla! Documentation

Revision as of 04:28, 21 January 2010 by Hasse bjork (Talk | contribs)

This works to send an email to the currently logged in user when used in a function in a model for a component and called from a view:

   $user =& JFactory::getUser();
   $message =& JFactory::getMailer();
   $message->setSubject('Your subject string');
   $message->setBody("Your body string\nin double quotes if you want to parse the \nnewlines etc");
   $sender = array( '', 'Sender Name' );
   $sent = $message->send();
   if ($sent != 1) echo 'Error sending email';

See also