PHP code example of txtmsg / php-sdk

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

    

txtmsg / php-sdk example snippets


use Txtmsg\PhpSdk\TxtmsgClient;

$client = new TxtmsgClient('your_api_key');

use Txtmsg\PhpSdk\TxtmsgClient;
use Txtmsg\PhpSdk\TxtmsgException;

$client = new TxtmsgClient('your_api_key');

try {
    $response = $client->sendSMS([
        'recipient' => '94771234567',
        'sender_id' => 'TXTMSG',
        'type'      => 'plain',
        'message'   => 'Hello from TXTMSG.lk!',
    ]);

    print_r($response);
} catch (TxtmsgException $e) {
    echo 'Error: ' . $e->getMessage();
}

$balance = $client->viewBalance();
print_r($balance);

$client->sendCampaign([
    'contact_list_id' => '6415907d0d37a',
    'sender_id'       => 'TXTMSG',
    'type'            => 'plain',
    'message'         => 'Campaign message',
    'schedule_time'   => '2025-12-20 07:00',
]);
bash
composer