PHP code example of gladdle / nexah-sms

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

    

gladdle / nexah-sms example snippets




laddle\NexahSms\Configuration;
use Gladdle\NexahSms\SmsClient;

$client = new SmsClient(
    new Configuration(
        "username",
        "password",
        "senderId"
    )
);

// Multiple numbers
// formats: 6xxxxxxxx or 2376xxxxxxxx
$client->send("6xxxxxxxx, 2376xxxxxxxx", "Message to be sent"); // returns true

// One number
$client->send("6xxxxxxxx", "Message to be sent"); // returns true

// Get SMS balance
$client->getBalance() // returns number, eg 10000


use Gladdle\NexahSms\Exception\AuthException;
use Gladdle\NexahSms\Exception\SendingFailureException;

try {

    $client->send("6xxxxxxxx, 2376xxxxxxxx", "Message to be sent");
    $client->getBalance();

} catch (AuthException $e) {
    // Wrong username and/or password 
    // do stoff...
} catch (SendingFailureException $e) {
    // Incorrect numbers. Message not sent
    // Retrieve them
    $numbers = $client->getInvalidNumbers(); // ['6xxxxxxxxx', 'xxxxxxxxx'];
}


$client = new SmsClient(
    new Configuration(
        "username",
        "password",
        "senderId"
        __DIR__ . '/var/logs.log'
    )
);