PHP code example of pratiksahu2003 / smscountry-php-sdk

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

    

pratiksahu2003 / smscountry-php-sdk example snippets




declare(strict_types=1);

ountry\Database\PdoSmsLogger;
use SMSCountry\MessageType;
use SMSCountry\SMSCountryClient;

// Load .env manually if needed (or use vlucas/phpdotenv)
// putenv('SMS_COUNTRY_AUTH_KEY=...');

$config = Config::fromEnv();
$pdo = new PDO('mysql:host=127.0.0.1;dbname=myapp;charset=utf8mb4', 'root', 'secret');
$logger = new PdoSmsLogger($pdo, 'smscountry_logs');
$client = new SMSCountryClient($config, logger: $logger);

// Local number — country code 91 is added automatically
$result = $client->send('9876543210', 'Hello from SMS Country!', MessageType::Normal);

echo 'Job ID: ' . $result->messageId . PHP_EOL;
echo 'Status: ' . ($result->success ? 'sent' : 'failed') . PHP_EOL;

$balance = $client->getBalance();
echo 'Credits: ' . $balance->balance;

use SMSCountry\Laravel\Facades\SMSCountry;
use SMSCountry\MessageType;

SMSCountry::send('9876543210', 'Your OTP is 482910', MessageType::Normal);

use SMSCountry\Contracts\SMSCountryClientInterface;
use SMSCountry\MessageType;

class OtpController extends Controller
{
    public function __construct(private SMSCountryClientInterface $sms) {}

    public function sendOtp(Request $request)
    {
        $result = $this->sms->send(
            mobileNumber: $request->phone,   // e.g. 9876543210
            message: 'Your OTP is 482910. Valid for 5 minutes.',
            type: MessageType::Normal,
        );

        return response()->json([
            'job_id' => $result->messageId,
            'status' => 'sent',
        ]);
    }
}

use SMSCountry\Laravel\Models\SmsLog;

$logs = SmsLog::query()
    ->where('status', 'sent')
    ->latest()
    ->paginate(20);

use SMSCountry\Config;
use SMSCountry\SMSCountryClient;

public static function smsCountry(bool $getShared = true)
{
    if ($getShared) {
        return static::getSharedInstance('smsCountry');
    }

    return new SMSCountryClient(Config::fromEnv([
        'SMS_COUNTRY_AUTH_KEY' => env('SMS_COUNTRY_AUTH_KEY'),
        'SMS_COUNTRY_AUTH_TOKEN' => env('SMS_COUNTRY_AUTH_TOKEN'),
        'SMS_COUNTRY_BASE_URL' => env('SMS_COUNTRY_BASE_URL'),
        'SMS_COUNTRY_SENDER_ID' => env('SMS_COUNTRY_SENDER_ID'),
        'SMS_COUNTRY_DEFAULT_COUNTRY_CODE' => env('SMS_COUNTRY_DEFAULT_COUNTRY_CODE'),
    ]));
}

$sms = service('smsCountry');
$sms->send('9876543210', 'Hello from CodeIgniter!');

public function __construct(
    private SMSCountryClientInterface $sms,
) {}

public function notify(string $phone, string $message): void
{
    $this->sms->send($phone, $message);
}

define('SMS_COUNTRY_AUTH_KEY', 'your_username');
define('SMS_COUNTRY_AUTH_TOKEN', 'your_password');
define('SMS_COUNTRY_BASE_URL', 'https://api.smscountry.com');
define('SMS_COUNTRY_SENDER_ID', 'SUGNTA');
define('SMS_COUNTRY_DEFAULT_COUNTRY_CODE', '91');



use SMSCountry\Config;
use SMSCountry\SMSCountryClient;

$config = Config::fromEnv([
    'SMS_COUNTRY_AUTH_KEY' => SMS_COUNTRY_AUTH_KEY,
    'SMS_COUNTRY_AUTH_TOKEN' => SMS_COUNTRY_AUTH_TOKEN,
    'SMS_COUNTRY_BASE_URL' => SMS_COUNTRY_BASE_URL,
    'SMS_COUNTRY_SENDER_ID' => SMS_COUNTRY_SENDER_ID,
    'SMS_COUNTRY_DEFAULT_COUNTRY_CODE' => SMS_COUNTRY_DEFAULT_COUNTRY_CODE,
]);

$client = new SMSCountryClient($config);
$client->send('9876543210', 'Order confirmed!');

$result = $client->send('9876543210', 'Hello!');
// $result->messageId  →  "515789649"
// $result->success    →  true
// $result->rawResponse → "OK:515789649"

$client->sendBulk(
    ['9876543210', '9123456789', '9988776655'],
    'Flash sale starts now!',
);

$client->sendMultiple([
    '9876543210' => 'Hi Rahul, your order is ready.',
    '9123456789' => 'Hi Priya, your order is ready.',
]);

$client->send('9876543210', 'Hello!', senderId: 'SUGNTA');

$balance = $client->getBalance();

if ($balance->success) {
    echo 'Remaining credits: ' . $balance->balance;
} else {
    echo 'Error: ' . $balance->rawResponse;
}

$from = new DateTime('2026-06-01 00:00:00');
$to   = new DateTime('2026-06-24 23:59:59');

$reports = $client->getDeliveryReports($from, $to);

foreach ($reports as $report) {
    echo sprintf(
        "Job %s → %s (%s)\n",
        $report->jobId,
        $report->status?->label() ?? 'Unknown',
        $report->mobileNumber,
    );
}

use SMSCountry\Support\DeliveryWebhookHandler;

$handler = new DeliveryWebhookHandler($logger);
$handler->handle($_GET);
// Params: jobno, mobilenumber, status, doneTime, messagepart

use Illuminate\Http\Request;
use SMSCountry\Support\DeliveryWebhookHandler;

Route::get('/sms/delivery-callback', function (Request $request) {
    app(DeliveryWebhookHandler::class)->handle($request->query());
    return response('OK', 200);
});

use SMSCountry\MessageType;

$client->send('9876543210', 'नमस्ते', MessageType::Unicode);
$client->send('9876543210', 'Your OTP: 482910', MessageType::Normal);

use SMSCountry\DeliveryStatus;

$status = DeliveryStatus::Delivered;
echo $status->label(); // "Delivered"
bash
composer 
bash
mysql -u root -p your_database < vendor/pratiksahu2003/smscountry-php-sdk/database/schema/smscountry_logs.sql
bash
php artisan vendor:publish --tag=smscountry-migrations
php artisan migrate
bash
composer 
bash
mysql -u root -p myapp < vendor/pratiksahu2003/smscountry-php-sdk/database/schema/smscountry_logs.sql
bash
composer 
bash
php artisan vendor:publish --tag=smscountry-config
php artisan vendor:publish --tag=smscountry-migrations
php artisan migrate
bash
git clone https://github.com/Pratiksahu2003/smscountry-php-sdk.git
cd smscountry-php-sdk
composer install
composer test