I am looking at this https://book.cakephp.org/3.0/en/core-libraries/email.html#creating-reusable-emails
I follow the manual to create something like this:
<?php
namespace App\Mailer;
use Cake\Mailer\Mailer;
class ArticleMailer extends Mailer
{
public function implementedEvents()
{
return [
'Model.afterSave' => 'onPost'
];
}
public function onPost(Event $event, EntityInterface $entity, ArrayObject $options)
{
if ($entity->isNew()) {
$this->send('newarticle', [$entity]);
}
}
public function newarticle($article)
{
$this
->setTo('info@gmail.com')
->setSubject(sprintf('New article posted %s', $article->name))
->setViewVars($article->toArray())
->setTemplate('newArticle');
}
}
According to the manual this should work fine, but when adding a new article it does not get triggered? Am I missing some extra step I need to do that is not mentioned in the manual?