Actions

Sending email from extensions

From Joomla! Documentation

Revision as of 08: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->addRecipient($user->email);
  $message->setSubject('Your subject string');
  $message->setBody("Your body string\nin double quotes if you want to parse the \nnewlines etc");
  $sender = array( 'sender@email.address.org', 'Sender Name' );
  $message->setSender($sender);
  $sent = $message->send();
  if ($sent != 1) echo 'Error sending email';