SimpleNotificator

SimpleNotificator is a simple script that allows you to send customized trigger-based email notifications.

SimpleNotificator - sends trigger-based email notifications

Erstellt am: Saturday 25 August 2018  |  Letzte Änderung am: Wednesday 29 August 2018

These notifications are called trigger-based email notifications, and are designed to keep you informed about events triggered by visitors to your website.

Configuring script by using configuration file

The SimpleNotificator, through configuration file, gives you control over the way script run and you can define the default text for your message and your email account settings. You can change parameter in configuration file to define which parameters the script should use by default. The configuration file can be found in the root directory /snotificator/config.php.

Here’s a quick walkthrough of the plugin in action

Let's test the script in practice and write a function that will sent an email notification to the administrator when a logged on user calls a certain page. The check whether the user is logged in can differ from system to system, in my example, I use a simple session-based authentication, but your check should depends on the system you are using.

Altogether only one file is needed I just call it private-page.php.

<?php
include 'snotificator/notify.php';

if($_SESSION['loggedin'] && !isset($_SESSION['sent'])) {
	$controller->execute();
	$_SESSION['sent'] = true;
}

Note, to prevent the message from being sent again, the session variable sent is set to true.

Of course, you can also change the text for your messages at runtime. All you have to do is pass your own configuration to the controller. You can use your own configuration file or modify the existing configuration parameters:

<?php
include 'snotificator/notify.php';

if($_SESSION['loggedin'] && !isset($_SESSION['sent'])) {
    // Modify the existing config params
    $config = new \Notify\Config();
    // ... or use custom config file
    // $config = new \Notify\Config(__DIR__.'/custom-config.php');
    $config->emailSubject = 'New Subject';
    $config->emailBody = 'New message body ...';
    $controller->execute($config);
    $_SESSION['sent'] = true;
}

Autor: Bigin  |  Tags:  PHPScriptsDevelopment