SDK
v0.1.0
PHP SDK
The official PHP SDK for Sendexa. One package, one client, every API — SMS, OTP, WhatsApp, Email, Voice, and Webhook verification.
Zero Dependencies
Uses only PHP built-ins — ext-curl and ext-json. No Composer bloat.
Framework Agnostic
Works in Laravel, Symfony, WordPress, plain PHP, and any SAPI.
Strictly Typed
Full declare(strict_types=1), readonly properties, and PHPDoc types throughout.
PHP 8.1+
Leverages named arguments, readonly properties, and intersection types.
Installation
Bash
composer require sendexa/sdk
Requirements
PHP 8.1 or later with
ext-curl and ext-json enabled. Both extensions are included in standard PHP distributions.Initialise the Client
Create one client instance per application and reuse it — the client is stateless and safe to share across requests.
PHP
<?phpuse Sendexa\Sendexa;$client = new Sendexa(apiKey: $_ENV['SENDEXA_API_KEY'],apiSecret: $_ENV['SENDEXA_API_SECRET'],);
API Examples
Send single and bulk SMS messages with delivery tracking.
PHP
// Send a single SMS$response = $client->sms->send('0244123456', 'MyBrand', 'Your order #1234 has been confirmed!');echo $response['data']['messageId'] . PHP_EOL;// Send bulk SMS$client->sms->sendBulk(from: 'MyBrand',messages: [['to' => '0244123456', 'message' => 'Hi Alice!'],['to' => '0555987654'], // uses shared message],message: 'Hello from MyBrand!',);// Check delivery status$status = $client->sms->getStatus($response['data']['messageId']);echo $status['data']['status']; // "delivered"// Resend a failed message$client->sms->resend($response['data']['messageId']);
Error Handling
All API errors throw a SendexaException with structured properties for easy branching.
PHP
use Sendexa\Sendexa;use Sendexa\SendexaException;try {$client->sms->send('0244123456', 'MyBrand', 'Hi!');} catch (SendexaException $e) {echo $e->status; // HTTP status e.g. 403echo $e->code; // API code e.g. "SENDER_ID_NOT_APPROVED"echo $e->getMessage();// Human text e.g. "Sender ID not approved"echo $e->requestId; // Trace ID for Sendexa support}
| Property | Type | Description |
|---|---|---|
| $e->status | int | HTTP status code (400, 401, 403, 429…) |
| $e->code | string | Machine-readable error code from the API |
| $e->getMessage() | string | Human-readable description of the error |
| $e->requestId | string|null | Sendexa trace ID — include when contacting support |
| $e->raw | mixed | The full raw error payload from the API |
Best Practices
- Create one
Sendexainstance (e.g. in a service container) and reuse it — do not instantiate per request - Store credentials in environment variables or a secrets manager, never in source code
- Always call
$client->webhooks->verify()before processing any webhook event - Catch
SendexaExceptionseparately from generic exceptions so you can branch on$e->code - Pass a custom
timeoutif your environment has strict request limits (default: 30 s)