Send Email Notifications

Plesk SDK API gives you the ability to send customized email notifications. The notification SDK API consists of two parts:

  • A hook which describes a list of notifications with their default settings. These settings can be changed in Plesk (Tools & Settings => Notifications).
  • A manager (the pm_Notification class) provides the send() method for sending notifications.
Examples

To configure the default notification settings:

plib/hooks/Notifications.php

class Modules_WpToolkit_Notifications extends pm_Hook_Notifications
{
    public function getNotifications()
    {
        return [
            'domain_create' => [
                'title' => '',                                   // notification's title which admin sees in UI
                'notifyAdmin' => true,                           // by default notify admin
                'notifyResellers' => false,                      // by default notify resellers
                'notifyClients' => false,                        // by default notify clients
                'notifyCustomEmail' => false,                    // by default send notification to a custom email
                'customEmail' => '',                             // custom email address to notify
                'subject' => 'Custom Subject <testsubjecttag>',  // subject of email (placeholders allowed)
                'message' => 'Custom Body <testbodytag>'         // email's body (placeholders allowed)
            ]
        ];
    }
}

These settings can be changed in Plesk (Tools & Settings => Notifications).

To send a notification:

$notification = new \pm_Notification();
$recipients = $notification->send('domain_create');

To send notification to a some client with placeholders (Client gets it if only notifyClients setting is true):

$notification = new \pm_Notification();
$recipients = $notification->send(
    'domain_create',
    [
        'testsubjecttag' => 'Subject Placeholder',
        'testbodytag' => 'Body Placeholder',
    ],
    new \pm_Client(3)
);