-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathemail-custom-handler.php
47 lines (37 loc) · 1.48 KB
/
email-custom-handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require __DIR__ . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
// import namespaces
use Namshi\Notificator\Notification\Handler\Email as EmailHandler;
use Namshi\Notificator\Manager;
use Namshi\Notificator\Notification;
use Namshi\Notificator\Notification\Email\EmailNotificationInterface;
use Namshi\Notificator\Notification\Email\EmailNotification;
use Namshi\Notificator\NotificationInterface;
// create the handler
class SimpleEmailHandler extends EmailHandler
{
public function handle(NotificationInterface $notification)
{
$to = implode(',', $notification->getRecipientAddresses());
mail($to, $notification->subject, $notification->body);
}
}
$handler = new SimpleEmailHandler();
// create the manager and assign the handler to it
$manager = new Manager();
$manager->addHandler($handler);
// create the notification
class SimpleEmailNotification extends EmailNotification implements EmailNotificationInterface
{
public $subject;
public $body;
public function __construct($emailTemplate, $recipientAddress, $subject, $body, array $parameters = array())
{
parent::__construct($emailTemplate, $recipientAddress, $parameters);
$this->subject = $subject;
$this->body = $body;
}
}
$notification = new SimpleEmailNotification('test_email', '[email protected]', 'Test email', 'Hello!');
// trigger the notification
$manager->trigger($notification);