PHP code example of gsoftware / cloudsms-php

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

    

gsoftware / cloudsms-php example snippets


use GSoftware\CloudSMS\CloudSMSClient;

// Initialize the client
$client = new CloudSMSClient(
    'your-api-token',
    'your-sender-id'
);

// Check your balance
$balanceResponse = $client->getBalance();
if ($balanceResponse['status'] === 'success') {
    echo "Current balance: " . $balanceResponse['data'];
}

// Send an SMS
$smsResponse = $client->sendSMS(
    '+1234567890',
    'Hello from CloudSMS!'
);
if ($smsResponse['status'] === 'success') {
    echo "SMS sent successfully!";
} else {
    echo "Error: " . $smsResponse['message'];
}

$recipients = ['+1234567890', '+9876543210'];
$response = $client->sendSMS(
    $recipients,
    'Hello from CloudSMS!'
);

$scheduleTime = new DateTime('2024-12-20 07:00:00');
$response = $client->sendSMS(
    '+1234567890',
    'This is a scheduled message',
    null, // Use default sender ID
    $scheduleTime
);

$contactListIds = ['6415907d0d37a', '6415907d0d7a6'];
$response = $client->sendCampaign(
    $contactListIds,
    'This is a campaign message'
);

// Get details of a specific SMS
$smsDetails = $client->getSMS('606812e63f78b');
print_r($smsDetails);

$campaignDetails = $client->getCampaign('campaign_uid_here');
print_r($campaignDetails);

[
    'status' => 'success',
    'data' => 'response data here'
]

[
    'status' => 'error',
    'message' => 'A human-readable description of the error'
]
bash
composer