Hi guys,
I've got a scenario where if a moderator approves a dataobject (entry) within ModelAdmin (alters its status from Pending to Public), the submitter of the entry gets notified by email.
My code is as below:
function onAfterWrite(){
$changed = $this->getChangedFields();
if(isset($changed['EntryStatus'])){
if($changed['EntryStatus']['before'] == 'Pending' && $changed['EntryStatus']['after'] == 'Public'){
/* -- SEND USER EMAIL --*/
$From = SERVERFROM;
$entry = $this;
$To = $entry->Email;
$Subject = 'Entry Approved';
$email = new Email($From, $To, $Subject);
//$email->setTemplate('EmailAdmin');
$data['Image'] = $data['Link'] = '';
$data['Message'] = 'Your message has been approved'.;
$data['Feature'] = 'Your entry id is '.$entry->UniqueID;
//$email->populateTemplate($data);
$email->send();
}
}
parent::onAfterWrite();
}
The email sends fine if I send it without using a template. However, if I try to use a template, I get the eternal spinning Save in ModelAdmin, and no emails are sent. Nothing in the error logs. The template exists as I'm using it to send other emails within page controllers.
Has anyone come across this before?