1. Go to this page and download the library: Download nikba/sms.md-php-api 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/ */
nikba / sms.md-php-api example snippets
use Nikba\SmsMdPhpApi\SmsMd;
$sms = new SmsMd('YOUR_API_TOKEN');
$result = $sms->sendMessage(
to: '69123456',
text: 'Your code is 1234',
from: 'sms.md',
);
echo $result['id']; // message UUID
echo $result['segments']; // billed segments
echo $result['cost']; // e.g. "0.30"
$sms->sendMessage('69123456', 'Hello World!', 'sms.md');
// Scheduled (Europe/Chisinau local time, up to 30 days ahead):
$sms->sendMessage('69123456', 'Reminder', 'sms.md', sendAt: '2026-08-07 14:30:00');
$e = $sms->estimate('69123456', 'Мама мыла раму'); // Cyrillic → UCS-2
echo $e['segments']; // number of SMS
echo $e['encoding']; // "gsm-7" | "ucs-2"
echo $e['cost']; // total, as a string
// Send a code through an OTP application (Settings → OTP):
$sms->sendOtp('69123456', 'YOUR_OTP_APP_KEY', action: 'login');
// Verify what the user entered — returns true, or throws on a wrong/expired code:
try {
$sms->verifyOtp('69123456', '482913', 'YOUR_OTP_APP_KEY', action: 'login');
// ok
} catch (\Nikba\SmsMdPhpApi\Exception\ApiException $e) {
// invalid or expired
}
use Nikba\SmsMdPhpApi\Enum\MessageStatus;
$page = $sms->listMessages(['status' => MessageStatus::Delivered], page: 1);
foreach ($page['data'] as $message) { /* ... */ }
$page['meta']; // pagination info
$sms->getMessage('449d5410-82d3-4b6e-96bc-cc92a33eb3f5');
$sms->getBulkMessages('BULK_ID');
$sms->messageStatuses(); // status id → name reference
use Nikba\SmsMdPhpApi\Enum\Destination;
$r = $sms->sendMessage('+40712345678', 'Salut', 'sms.md');
Destination::from($r['destination']); // Destination::International
$r['countryIso']; // "RO"
$r['countryName']; // "Romania"
$r['cost']; // provider price, depends on the country
try {
$sms->sendMessage('+40712345678', 'Salut', 'sms.md');
} catch (\Nikba\SmsMdPhpApi\Exception\ValidationException $e) {
echo $e->firstError('_'); // "…International numbers are not supported for your account."
}
$r = $sms->sendBulk(['69123456', '+1202555000'], 'Hi', 'sms.md');
$r['queued']; // how many were actually sent
$r['rejected']; // numbers skipped because their country isn't allowed
echo $sms->getBalance(); // "123.45" (string, to preserve precision)
use Nikba\SmsMdPhpApi\Exception\ApiException;
use Nikba\SmsMdPhpApi\Exception\ValidationException;
use Nikba\SmsMdPhpApi\Exception\InsufficientBalanceException;
try {
$sms->sendMessage('69123456', 'Hi', 'sms.md');
} catch (ValidationException $e) {
$e->getErrors(); // ['to' => ['The number is invalid.']]
$e->firstError('to');
} catch (InsufficientBalanceException $e) {
// top up the account
} catch (ApiException $e) {
$e->getErrorCode(); // e.g. RATE_LIMIT_EXCEEDED
$e->getHttpCode(); // 429
}
use Nikba\SmsMdPhpApi\Enum\Encoding;
Encoding::Gsm7->singleSegmentLength(); // 160
Encoding::Ucs2->singleSegmentLength(); // 70
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;
$guzzle = new Client(['timeout' => 10]);
$factory = new HttpFactory();
$sms = new SmsMd('YOUR_API_TOKEN', $guzzle, $factory, $factory);