Sending email from extensions

From Joomla! Documentation

Revision as of 07:30, 19 July 2008 by Rogerco (Talk | contribs)

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

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';