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/ConfigDefaults.php

<?php
// Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved.
 
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();
$recepients = $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();
$recepients = $notification->send(
    'domain_create',
    [
        'testsubjecttag' => 'Subject Placeholder',
        'testbodytag' => 'Body Placeholder',
    ],
    new \pm_Client(3)
);
 

Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.