Reputation: 93
I'm developing a Joomla plugin with onContentAfterSave event to send an email after saving a new articles.
the event are triggered when i save a new menu item or a new category. but not for new article.
Joomla! 3.7.5
public function onContentAfterSave($context, $article, $isNew){
$link = JRoute::_(ContentHelperRoute::getArticleRoute( $article->id, $article->catid ));
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'mailfrom' ),
$config->get( 'fromname' )
);
$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient = $user->email;
$recipient = array($recipient);
$mailer->addRecipient($recipient);
$body = '<p>Bonjour</p>'
.'Un nouveau <a href="'.$link.'">article</a> a été ajouté.';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('Nouveau article - BBN Times');
$mailer->setBody($body);
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
return true;
}
Upvotes: 1
Views: 194
Reputation: 4271
The onContentAfterSave
is triggered by the Joomla core, and not by the extension's model, which means it should be triggered by any content saving.
I can think of 2 reasons why it is not triggered in your case:
Upvotes: 0