Difference between revisions of "Sending email from extensions"
From Joomla! Documentation
(New page: 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 =& JFac...) |
Hasse bjork (talk | contribs) m (Added link to "Docs JFactory->getMailer" and tagge source as php) |
||
Line 1: | Line 1: | ||
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: | 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: | ||
− | + | <source lang="php"> | |
$user =& JFactory::getUser(); | $user =& JFactory::getUser(); | ||
$message =& JFactory::getMailer(); | $message =& JFactory::getMailer(); | ||
Line 10: | Line 10: | ||
$sent = $message->send(); | $sent = $message->send(); | ||
if ($sent != 1) echo 'Error sending email'; | if ($sent != 1) echo 'Error sending email'; | ||
+ | </source> | ||
+ | |||
+ | ===See also=== | ||
+ | * [http://docs.joomla.org/JFactory/getMailer Docs on JFactory->getMailer] |
Revision as of 05:28, 21 January 2010
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';