PHP code example of metarush / notifier

1. Go to this page and download the library: Download metarush/notifier library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

metarush / notifier example snippets



use MetaRush\Notifier\Notifier;
use MetaRush\Notifier\Exception;
use MetaRush\Notifier\Pushover\Builder as PushoverNotifier;
use MetaRush\Notifier\Email\Builder as EmailNotifier;
use MetaRush\EmailFallback\Builder as EmailBuilder;
use MetaRush\EmailFallback\Server;

// ------------------------------------------------

// define a Pushover notifier

// you can use `addAccount()` multiple times for additional accounts

$pushoverNotifier = (new PushoverNotifier)
                        ->addAccount('pushover_app_key', 'pushover_user_key')
                        ->setSubject('test subject')
                        ->setBody('test body')
                        ->build();

// ------------------------------------------------

// define an email notifier

// you can use multiple STMP servers for failover (see package `metarush/email-fallback` for more options)

$servers = [
        (new Server)
            ->setHost('smtp_host')
            ->setUser('smtp_user')
            ->setPass('smtp_pass'])
            ->setPort(465)
            ->setEncr('TLS')
];

$emailBuilder = (new EmailBuilder)
                    ->setServers($servers)
                    ->setTos(['[email protected]'])
                    ->setSubject('test subject')
                    ->setBody('test body')
                    ->setFromEmail('[email protected]');

$emailNotifier = (new EmailNotifier)
                    ->setEmailFallbackBuilder($emailBuilder)
                    ->build()

// ------------------------------------------------

// put them together and send

$notifiers = [
    $pushoverNotifier,
    $emailNotifier
];

(new Notifier($notifiers))
    ->send();