PHP code example of platform5 / sdk

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

    

platform5 / sdk example snippets




latform5\Sdk\Platform5;

$client = new Platform5('p5_live_abc123def456', 'http://localhost:8084');

// Send an SMS
$sms = $client->sms()->send([
    'to' => '+254712345678',
    'message' => 'Your appointment is confirmed for tomorrow at 10 AM.',
    'from' => 'MyBrand',
]);
echo $sms['message_id'];

// Send an email
$client->email()->send([
    'to' => '[email protected]',
    'subject' => 'Welcome',
    'body' => 'Hello!',
    'from' => 'MyBrand',
]);

// Check message status
$status = $client->messages()->get('msg-uuid');

// Check balance
$balance = $client->account()->getBalance();

new Platform5(
    apiKey: 'p5_live_abc123',
    baseUrl: 'http://localhost:8084',  // optional
);

use Platform5\Sdk\Exception\RateLimitException;
use Platform5\Sdk\Exception\Platform5Exception;

try {
    $client->sms()->send([...]);
} catch (RateLimitException $e) {
    echo "Rate limited: {$e->remaining}/{$e->limit}";
} catch (Platform5Exception $e) {
    echo "API error {$e->statusCode}: {$e->getMessage()}";
}