PHP code example of falcongateway / notify

1. Go to this page and download the library: Download falcongateway/notify 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/ */

    

falcongateway / notify example snippets


use FalconGateway\Notify\FalconClient;
use FalconGateway\Notify\Channels\SMS;
use FalconGateway\Notify\Channels\Email;

$client = new FalconClient('your-platform-token');

// Send SMS
$result = $client->send(new SMS('Hello!'), ['+255712345678']);

// Send Email
$result = $client->send(new Email('Subject', 'Body text'), ['[email protected]']);

echo $result->message; // "Dispatched successfully."

new SMS('Your OTP is 1234')

(new Email('Subject', 'Plain text body'))
    ->html('<b>HTML body</b>')
    ->fromName('Falcon')
    ->fromEmail('[email protected]')
    ->replyTo('[email protected]')
    ->attachment(file_get_contents('invoice.pdf'), 'invoice.pdf')

(new Push('Title', 'Body'))
    ->data(['order_id' => '123'])
    ->imageUrl('https://example.com/image.png')

// Text message
new WhatsApp('Hello from Falcon!')

// Template message
(new WhatsApp(''))->template('otp_v1', ['1234', '5'])

(new Matrix('Alert: server down'))
    ->html('<b>Alert:</b> server down')

$result = $client->send(
    [new SMS('Code: 1234'), new Email('OTP', 'Code: 1234')],
    [['phone' => '+255712345678', 'email' => '[email protected]']]
);

$result = $client->sendToPhonebook(new SMS('Broadcast message'), ['PB-ABCD12']);

$result = $client->sendMessages([
    [
        'recipient' => ['phone' => '+255712345678'],
        'channels'  => ['sms' => true],
        'content'   => ['sms' => ['text' => 'Hi Alice!']],
    ],
]);

use FalconGateway\Notify\Schedule\Schedule;

// One-time
$client->send(new SMS('Reminder'), $recipients, Schedule::once('2026-09-01T09:00:00Z'));

// Daily at 8 AM
$client->send(new SMS('Good morning!'), $recipients, Schedule::daily8am('Africa/Dar_es_Salaam'));

// Custom cron expression
$client->send(new SMS('Weekly'), $recipients, Schedule::cron('0 8 * * MON', 'Africa/Nairobi'));

// Interval (every N minutes)
$client->send(new SMS('Ping'), $recipients, Schedule::interval(30, 'UTC'));

use FalconGateway\Notify\Exceptions\AuthException;
use FalconGateway\Notify\Exceptions\ValidationException;
use FalconGateway\Notify\Exceptions\ServerException;
use FalconGateway\Notify\Exceptions\NetworkException;

try {
    $client->send(new SMS('Hello'), $recipients);
} catch (AuthException $e) {
    // Invalid or inactive token (HTTP 403)
} catch (ValidationException $e) {
    // Bad request — check $e->getMessage() (HTTP 400)
} catch (ServerException $e) {
    // Gateway server error (HTTP 5xx)
} catch (NetworkException $e) {
    // Connection or timeout error
}