PHP code example of timothydake / nigeriabulksms-sdk
1. Go to this page and download the library: Download timothydake/nigeriabulksms-sdk 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/ */
timothydake / nigeriabulksms-sdk example snippets
igeriaBulkSMS\NigeriaBulkSMS;
use NigeriaBulkSMS\Exception\NigeriaBulkSMSException;
$username = "YOUR_USERNAME";
$password = "YOUR_PASSWORD";
$client = new NigeriaBulkSMS($username, $password);
try {
// Send an SMS
$smsResponse = $client->sms()->send(
"Hello from NigeriaBulkSMS PHP SDK!",
"YourApp",
"2348030000000"
);
echo "SMS sent successfully: " . json_encode($smsResponse) . "\n";
// Get account balance
$balanceResponse = $client->dataFetcher()->getBalance();
echo "Account Balance: " . json_encode($balanceResponse) . "\n";
} catch (NigeriaBulkSMSException $e) {
echo "Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")\n";
} catch (Exception $e) {
echo "An unexpected error occurred: " . $e->getMessage() . "\n";
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use NigeriaBulkSMS\Laravel\NigeriaBulkSMSFacade as NigeriaBulkSMS;
use NigeriaBulkSMS\Exception\NigeriaBulkSMSException;
class SMSController extends Controller
{
public function sendSMS(Request $request)
{
try {
$response = NigeriaBulkSMS::sms()->send(
"Hello from Laravel!",
"LaravelApp",
"2348030000000"
);
return response()->json(["status" => "success", "data" => $response]);
} catch (NigeriaBulkSMSException $e) {
return response()->json(["status" => "error", "message" => $e->getMessage(), "code" => $e->getCode()], 500);
} catch (Exception $e) {
return response()->json(["status" => "error", "message" => "An unexpected error occurred: " . $e->getMessage()], 500);
}
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use NigeriaBulkSMS\NigeriaBulkSMS;
use NigeriaBulkSMS\Exception\NigeriaBulkSMSException;
class SMSController extends Controller
{
protected $nigeriaBulkSMS;
public function __construct(NigeriaBulkSMS $nigeriaBulkSMS)
{
$this->nigeriaBulkSMS = $nigeriaBulkSMS;
}
public function sendSMS(Request $request)
{
try {
$response = $this->nigeriaBulkSMS->sms()->send(
"Hello from Laravel with DI!",
"LaravelDI",
"2348030000000"
);
return response()->json(["status" => "success", "data" => $response]);
} catch (NigeriaBulkSMSException $e) {
return response()->json(["status" => "error", "message" => $e->getMessage(), "code" => $e->getCode()], 500);
} catch (Exception $e) {
return response()->json(["status" => "error", "message" => "An unexpected error occurred: " . $e->getMessage()], 500);
}
}
}
new NigeriaBulkSMS(string $username, string $password)
$response = $client->sms()->send("Your message", "SenderID", "2348030000000");
// Or for multiple recipients:
$response = $client->sms()->send("Your message", "SenderID", ["2348030000000", "2348020000000"]);
$response = $client->call()->sendTTS("Hello, this is a test call.", "YourApp", "2348030000000");
$response = $client->call()->sendAudio("your-audio-reference-id", "YourApp", "2348030000000");
$response = $client->audio()->upload("https://example.com/my_audio.mp3");
// The response will contain a 'reference' which can be used with sendAudio.
$balance = $client->dataFetcher()->getBalance();
$profile = $client->dataFetcher()->getProfile();
$contacts = $client->dataFetcher()->getContacts();
$numbers = $client->dataFetcher()->getNumbers();
$groups = $client->dataFetcher()->getGroups();
$audios = $client->dataFetcher()->getAudios();
$history = $client->dataFetcher()->getHistory();
$scheduled = $client->dataFetcher()->getScheduled();
$reports = $client->dataFetcher()->getReports();
$payments = $client->dataFetcher()->getPayments();
use NigeriaBulkSMS\NigeriaBulkSMS;
use NigeriaBulkSMS\Exception\NigeriaBulkSMSException;
$client = new NigeriaBulkSMS("YOUR_USERNAME", "YOUR_PASSWORD");
try {
$response = $client->sms()->send("Test message", "TestApp", "2348000000000");
print_r($response);
} catch (NigeriaBulkSMSException $e) {
echo "API Error: " . $e->getMessage() . " (Code: " . $e->getCode() . ")\n";
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
echo "HTTP Error: " . $e->getMessage() . "\n";
} catch (Exception $e) {
echo "General Error: " . $e->getMessage() . "\n";
}
bash
php artisan vendor:publish --provider="NigeriaBulkSMS\\Laravel\\NigeriaBulkSMSServiceProvider"