Hi,
thanks for all of this so far. This is a really useful thread. It just won't work for me just yet. I pretty much copied everything from Marijn into my Silverstripe project, i.e.:
/mysite/_config.php
DataObject::add_extension('PageComment', 'PageCommentEmailNotification');
/mysite/code/PageCommentEmailNotification.php
<?php
class PageCommentEmailNotification extends DataObjectDecorator {
function onAfterWrite() {
$email = new Email();
$email->setTemplate('NewComment');
$email->setTo('email@domain.com');
$email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
$email->populateTemplate(Member::currentUser());
$email->populateTemplate(array(
'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
'PageTitle' => $this->owner->Parent()->Title,
'Comment' => $this->owner->Comment,
));
$email->send();
}
}
?>
/themes/mytheme/email/NewComment.ss
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
</head>
<body>
<p>At $Created, $Name posted a new comment on the page <a href="$URL">$PageTitle</a>.</p>
<p>Their comment:<br/>
$Comment</p>
<p>You can <a href="{$BaseHref}admin/comments/">administrate the comment</a>.</p>
</body>
</html>
No error message, but I never receive any email.
I ran dev/build?flush=all (in case that's necessary).
I also tried Object::add_extension instead of DataObject::add_extension ...
The project is on Silverstripe 2.3.5
What am I missing? Any hint is highly appreciated.
Cheers!
Anatol