Skip to Content
SDKsPHP

PHP SDK

Installation

composer require sendafrica/sendafrica-php

Quick Start

<?php use SendAfrica\Client; $client = new Client(['api_key' => 'SA-your-api-key']); $balance = $client->credits->getBalance(); echo "Credits: " . $balance->credits; $response = $client->sms->send([ 'to' => '+255712345678', 'message' => 'Hello from SendAfrica!', ]); echo "Message ID: " . $response->message_id;

API Reference

// Send bulk SMS $response = $client->sms->sendBulk([ 'recipients' => ['+255712345678', '+255787654321'], 'message' => 'Sale announcement!', ]); // List contacts $contacts = $client->contacts->list(['list_id' => '1']); // Create campaign $campaign = $client->campaigns->create([ 'name' => 'Summer Sale', 'contact_group_id' => '2', 'message' => 'Get 30% off!', ]);

Error Handling

<?php use SendAfrica\Exceptions\SendAfricaException; use SendAfrica\Exceptions\AuthenticationException; try { $response = $client->sms->send(['to' => '+255712345678', 'message' => 'Hello!']); } catch (AuthenticationException $e) { echo "Invalid API key: " . $e->getMessage(); } catch (SendAfricaException $e) { echo "API error: " . $e->getMessage(); }

Configuration

$client = new Client([ 'api_key' => 'SA-your-api-key', 'base_url' => 'https://api.sendafrica.online/v1', 'timeout' => 30, 'max_retries' => 3, ]);

Requirements

  • PHP 8.1+
  • ext-curl
  • ext-json
Last updated on