Elgg  Version master
SendEmailHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
11 
19  public function __invoke(\Elgg\Event $event) {
20  if ($event->getValue() === true) {
21  // assume someone else already sent the message
22  return;
23  }
24 
25  $message = $event->getParam('notification');
26  if (!$message instanceof \Elgg\Notifications\Notification) {
27  return false;
28  }
29 
30  $sender = $message->getSender();
31  $recipient = $message->getRecipient();
32  if (!$recipient->email) {
33  return false;
34  }
35 
37  'from' => $sender,
38  'to' => $recipient,
39  'subject' => $message->subject,
40  'body' => $message->body,
41  'params' => $message->params,
42  ]);
43 
44  return _elgg_services()->emails->send($email);
45  }
46 }
$email
Definition: change_email.php:7
static factory(array $options=[])
Create an email instance form an array of options.
Definition: Email.php:80
Notification container.
__invoke(\Elgg\Event $event)
Send an email notification.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
$recipient
Definition: mute.php:8
Models an event passed to event handlers.
Definition: Event.php:11