This repository contains the open source PHP client for Nigeriabulksms's API. Documentation can be found at: https://nigeriabulksms.com/sms-gateway-api-in-nigeria/
- Sign up for a free Nigeriabulksms account
- after signing up, your username and password will be used for authenticating with the APIs
- Nigeriabulksms API client for PHP requires PHP >= 7.4.
- Download composer
- Run
composer require ossycodes/nigeriabulksms-php
.
When you do not use Composer. You can git checkout or download this repository and include the Nigeriabulksms API client manually.
We have put some self-explanatory examples in the src/Examples directory, but here is a quick breakdown on how it works. First, you need to set up a Nigeriabulksms\Client. Be sure to replace YOUR_USERNAME and YOUR_PASSWORD with your real credentials.
require 'autoload.php';
$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);
That's easy enough. Now we can query the server for information. Lets use getting your balance overview as an example:
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());
}
Sending Text SMS Message
require_once(__DIR__ . '/../autoload.php');
$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());
}
Complete documentation, instructions, and examples are available at: https://nigeriabulksms.com/sms-gateway-api-in-nigeria/
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
Please buy me a cup of coffee https://www.paypal.com/paypalme/osaigbovoemmanuel , Leave a star and follow me on Twitter .