PHP code example of ossycodes / nigeriabulksms-php

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

    

ossycodes / nigeriabulksms-php example snippets




$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
            ->setUsername('YOUR_USERNAME')
            ->setPassword('YOUR_PASSWORD')
            ->setTimeout(10) //optional defaults to 10
            ->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);


try {

    // Get your balance
    $balance = $client->balance->read();

    var_dump($balance);
    
} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {

    // That means that your username and/or password is incorrect
    echo 'invalid credentials';

}
catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {

    // That means that your balance is insufficient
    echo 'insufficient balance';

}
catch (\Exception $e) {
 
 var_dump($e->getMessage());

}



$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
    ->setUsername('YOUR_USERNAME')
    ->setPassword('YOUR_PASSWORD')
    ->setTimeout(10) //optional defaults to 10
    ->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);

try {

    $message = new \Ossycodes\Nigeriabulksms\Objects\TextMessage();
    $message->sender = 'YOUR_SENDER_NAME';
    $message->recipients = '2342222222222';
    $message->body =  'body of text message goes in here'; //should be less than 160 characters
    
    //send the text sms message
    $response = $client->message->send($message);
    
    var_dump($response);

} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {

    // That means that your username and/or password is incorrect
    echo 'invalid credentials';

} catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {

    // That means that your balance is insufficient
    echo 'insufficient balance';

} catch (\Ossycodes\Nigeriabulksms\Exceptions\RequestDeniedException $e) {

    // That means that you do not have permission to perform this action
    echo 'this action is not permitted';

} catch (\Exception $e) {

    var_dump($e->getMessage());

}