Download the PHP package nikba/sms.md-php-api without Composer
On this page you can find all versions of the php package nikba/sms.md-php-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sms.md-php-api
sms.md PHP SDK
Modern PHP SDK for the sms.md v3 Client API — send single, bulk and one‑time‑code (OTP) SMS in Moldova, estimate cost, read delivery history, manage address books and check your balance.
- PHP 8.1+,
declare(strict_types=1)throughout - PSR‑18 HTTP client (bring your own, or auto‑discovered)
- Typed exceptions you can branch on, plus enums for statuses and encoding
- Targets the current v3 API; the deprecated v1 endpoints remain available via
->legacy()
📖 Changelog
Upgrading from 1.x? The v1 API this SDK used is now legacy. 2.0 is a rewrite around v3 with new method names and exception‑based error handling. See Migration.
Installation
The SDK talks to any PSR‑18 HTTP client. If you don't already have one, install Guzzle (it will be discovered automatically):
Quick start
- Create an API token in your account: Settings → API (
https://app.sms.md/settings/api). - Register and get approval for a sender name: Settings → Sender names.
- Send:
A token grants full access to the account and can spend your balance — keep it server‑side, never in mobile apps or frontend code.
Usage
Send an SMS
Recommended number format is national with no prefix (69123456). 069123456, 37369123456, +37369123456 and forms with spaces/dashes are accepted too.
Bulk send (up to 500 recipients)
Estimate cost before sending
One‑time codes (OTP)
Read messages
Supported listMessages filters: dateCreated[after], dateCreated[before], dateSent[after], dateSent[before], senderName, receiverNumber, status, order[desc].
Sender names
Address books & contacts
International sending
There is no separate method or parameter for foreign numbers — pass an international number to the same sendMessage() / sendBulk() / estimate() calls and the API detects the destination automatically. +373 77… (Transnistria) and any non‑Moldovan number count as international.
International sending must be enabled for your account (and may be restricted to specific countries). The response tells you the destination and country:
If international sending is disabled, a single send throws ValidationException with the reason under the _ key (not tied to a field):
In a bulk send, disallowed numbers are skipped individually rather than failing the whole batch — the rest still go out:
Use estimate() first to see the segment count and per‑country price without sending.
Balance
Error handling
Every failed request throws a typed exception. Branch on the machine‑readable code, never on the message — in production the message is replaced with a generic string.
| Exception | Error code(s) | HTTP |
|---|---|---|
AuthenticationException |
AUTHENTICATION_REQUIRED, INVALID_API_TOKEN |
401 |
InsufficientBalanceException |
INSUFFICIENT_BALANCE |
402 |
ForbiddenException |
FORBIDDEN, SCOPE_FORBIDDEN |
403 |
NotFoundException |
NOT_FOUND |
404 |
ValidationException |
VALIDATION_ERROR |
422 |
RateLimitException |
RATE_LIMIT_EXCEEDED |
429 |
ServerException |
INTERNAL_ERROR |
5xx |
TransportException |
— (network / non‑JSON response) | — |
All of the above extend SmsMdException, so you can catch that to handle any SDK failure at once.
Scopes
Each API token is created with a set of scopes; an endpoint whose scope the token lacks fails with 403 SCOPE_FORBIDDEN. Relevant scopes: messages:send, messages:read, otp:send, contacts:read, contacts:write, senders:read, account:read.
Billing
You're charged per segment. A single Cyrillic character switches the whole message to UCS‑2 (70 chars/segment instead of 160). Use estimate() or the Encoding enum to reason about segment sizes:
Injecting your own HTTP client
Any PSR‑18 client and PSR‑17 factories can be passed explicitly — useful for custom timeouts, retries, proxies or testing:
Legacy v1 API
The deprecated v1 endpoints remain reachable for backward compatibility:
Migration from 1.x
| 1.x | 2.0 |
|---|---|
$sms->sendSms($to, $msg, $from) |
$sms->sendMessage($to, $text, $from) |
$sms->getBalance() → int |
$sms->getBalance() → string |
$sms->getMessages($page, $from, $to, $status) |
$sms->listMessages($filters, $page) (returns data + meta) |
$sms->getMessage($id) |
$sms->getMessage($id) |
$sms->getMessageStatuses() |
$sms->messageStatuses() |
$sms->getSenderAliases() |
$sms->listSenderAliases() |
$sms->getContacts() / getAddressBooks() |
$sms->listAddressBookContacts() / listAddressBooks() |
| errors returned in the payload | typed exceptions thrown |
Auth moved from a ?token= query parameter to the X-Api-Token header, and sends are now POST … /v3/messages with a JSON body. Responses are wrapped in a {status, data, meta} envelope, which the SDK unwraps for you.
Testing
License
MIT — Free Software, Hell Yeah!
All versions of sms.md-php-api with dependencies
ext-json Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
php-http/discovery Version ^1.19