I’m trying to establish a mail alert, whenever an article is updated, using the page.update:after hook. When I’m saving an update to an article I always get:
Das Formular konnte nicht gespeichert werden
Exception: undefined. The JSON response from the API could not be parsed. Please check your API connection.
I’ve tried with two different mail servers. They both work when not used in a hook. Updated to Kirby 3.4 as I have read in other posts this would solve the JSON API Problem. Unfortunately did not for me. I have no clue what the problem is. Any hints?
This is my hook code (tried in config and as plugin, same result):
'hooks' => [
'page.update:after' => function($newPage, $oldPage){
$p = $newPage;
if($p->template()=='article' && $p->isListed()) {
$emailText = "some Text here ";
$kirby = kirby();
$bccarray = array();
foreach($kirby->users() as $theUser){
if(($theUser->notifyme() == 'true')) {
if(V::email($theUser->email())) {$bccarray[]=$theUser->email();};
if(V::email($theUser->email2())) {$bccarray[]=$theUser->email2();};
};
};
try {
$kirby->email(array(
'from' => 'aktuelles@mydomain.de',
'to' => 'webmaster@mydomain.de',
'bcc' => $bccarray,
'subject' => 'A new message has been created',
'body' => $emailText,
));
} //try
catch(Exception $e) {
echo $e->getMessage();
}
} //if template
} //Hook function code
]//hooks