Hello,
I couldn't find the topic, so im posting it again:
Got this little script:
PageCommentEmailNotification.php
<?php
class PageCommentEmailNotification extends DataObjectDecorator {
function onAfterWrite() {
parent::onAfterWrite();
if ($this->NeedsModeration) {
$email = new Email();
$email->setTemplate('NewComment');
$email->setTo(Email::getAdminEmail());
$email->addCustomHeader('Reply-To', Member::currentUser()->Email);
$email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
$email->populateTemplate(array(
'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
'PageTitle' => $this->owner->Parent()->Title,
'Comment' => $this->owner->Comment,
'Name' => $this->owner->Name,
));
$email->send();
}
}
}
It sends emails when new comments are posted on my blog, this works well when your logged in as a admin..
But when your not logged in: you get a pop-up with the html code of a error page. The message content:
<h2>Server error</h2>
<p>Sorry, there was a problem with handling your request.</p>
How do i fix this?