Elgg  Version 4.3
SendEmailHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Notifications;
4 
11 
19  public function __invoke(\Elgg\Hook $hook) {
20  if ($hook->getValue() === true) {
21  // assume someone else already sent the message
22  return;
23  }
24 
25  $message = $hook->getParam('notification');
26  if (!$message instanceof \Elgg\Notifications\Notification) {
27  return false;
28  }
29 
30  $sender = $message->getSender();
31  if (!$sender) {
32  return false;
33  }
34 
35  $recipient = $message->getRecipient();
36  if (!$recipient || !$recipient->email) {
37  return false;
38  }
39 
41  'from' => $sender,
42  'to' => $recipient,
43  'subject' => $message->subject,
44  'body' => $message->body,
45  'params' => $message->params,
46  ]);
47 
48  return _elgg_services()->emails->send($email);
49  }
50 }
__invoke(\Elgg\Hook $hook)
Send an email notification.
$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.
Models an event passed to hook handlers.
Definition: Hook.php:11
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
$recipient
Definition: mute.php:8