Download the PHP package sms-partners/php-sdk without Composer
On this page you can find all versions of the php package sms-partners/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sms-partners/php-sdk
More information about sms-partners/php-sdk
Files in sms-partners/php-sdk
Package php-sdk
Short Description Official PHP SDK for the SMS Partners API.
License MIT
Informations about the package php-sdk
SMS Partners PHP SDK
Official PHP SDK for the SMS Partners API.
Requirements
- PHP 8.1 or higher
- Composer
Installation
Getting Started
Generate an API key from the Developer → API Tokens section of your SMS Partners account, then create a client:
Sending SMS
With a custom Sender ID
Pass an approved Sender ID as the from argument to control how the message appears to the recipient:
The from value must match an approved Sender ID on your account. If omitted, the message is sent from the shared number pool.
Scheduling a message
Pass a \DateTimeInterface as scheduledAt to send the message at a future time. Credits are reserved immediately.
Credit cost
Credits are consumed based on message length and character encoding:
| Encoding | Single SMS | Per segment (multipart) |
|---|---|---|
| GSM-7 (standard ASCII) | 160 chars | 153 chars |
| Unicode (emoji, non-Latin) | 70 chars | 67 chars |
A single message can be up to 1,600 characters. Long messages are split into multiple segments and charged per segment.
SendResponse properties
SendResponse extends Message and adds a convenience to property.
| Property | Type | Description |
|---|---|---|
id |
int |
Message ID |
status |
string |
sending, scheduled, sent, failed |
body |
string |
Message body |
from |
?string |
Sender ID name or pool number used |
scheduledAt |
?DateTimeImmutable |
Scheduled send time, or null |
creditsUsed |
int |
Credits deducted |
createdAt |
DateTimeImmutable |
When the message was created |
recipients |
Recipient[] |
Delivery status per recipient |
to |
string |
Convenience — phone of the first recipient |
Credit Balance
Quickly check the current balance without fetching the full account object:
Messages
List messages
Retrieve your outbound message history, newest first. Results are paginated at 25 per page.
Filter by status
Available statuses: scheduled, queued, sending, sent, failed, cancelled.
Get a single message
Message properties
| Property | Type | Description |
|---|---|---|
id |
int |
Message ID |
status |
string |
Current message status |
body |
string |
Message body |
from |
?string |
Sender ID name or pool number used |
scheduledAt |
?DateTimeImmutable |
Scheduled send time, or null |
creditsUsed |
int |
Credits charged |
createdAt |
DateTimeImmutable |
When the message was created |
recipients |
Recipient[] |
Delivery status per recipient |
Recipient properties
| Property | Type | Description |
|---|---|---|
phone |
string |
Recipient phone number |
status |
string |
queued, sent, delivered, or failed |
deliveredAt |
?DateTimeImmutable |
Delivery confirmation time, or null |
errorMessage |
?string |
Failure reason, or null |
MessagePage properties
| Property | Type | Description |
|---|---|---|
data |
Message[] |
Messages on this page |
total |
int |
Total messages across all pages |
perPage |
int |
Page size (25) |
currentPage |
int |
Current page number |
lastPage |
int |
Last page number |
hasMore() |
bool |
Whether more pages exist |
Sender IDs
List all approved Sender IDs on your account. These are the values you can pass as from when sending:
SenderId properties
| Property | Type | Description |
|---|---|---|
id |
int |
Sender ID record ID |
name |
string |
The sender name (use this as the from value) |
status |
string |
Always approved |
Account
Fetch your full account details:
AccountResponse properties
| Property | Type | Description |
|---|---|---|
id |
int |
Account user ID |
name |
string |
Account holder name |
email |
string |
Account email address |
balanceCredits |
int |
Current credit balance |
status |
string |
active or suspended |
autoTopupEnabled |
bool |
Whether auto top-up is active |
autoTopupThreshold |
int |
Balance level that triggers top-up |
autoTopupAmount |
int |
Credits purchased on auto top-up |
Webhooks
SMS Partners can send webhook events to your server when a message is delivered or fails. Configure webhook endpoints from the Developer → Webhooks section of your account.
Verifying signatures
Every webhook request includes an X-Webhook-Signature header containing an HMAC-SHA256 signature of the raw request body. Always verify this before processing:
Parsing events
After verifying the signature, parse the payload into a typed event object:
Handling specific events
Full webhook handler example
WebhookEvent reference
| Property / Method | Type | Description |
|---|---|---|
event |
string |
message.delivered or message.failed |
timestamp |
DateTimeImmutable |
When the event occurred |
data |
array |
Full event payload |
isDelivered() |
bool |
True for message.delivered events |
isFailed() |
bool |
True for message.failed events |
messageId() |
?int |
ID of the related message |
recipientPhone() |
?string |
Recipient phone number |
Error Handling
All SDK methods throw exceptions that extend SmsPartners\Exceptions\SmsPartnersException. Catch the base class to handle all errors, or catch specific types for fine-grained control:
Exception reference
| Exception | Thrown when |
|---|---|
AuthenticationException |
API key is invalid or missing (HTTP 401) |
InsufficientCreditsException |
Insufficient credits (HTTP 402). Exposes balance and required. |
ValidationException |
Request failed validation (HTTP 422). Exposes errors keyed by field name. |
ApiException |
Unexpected API error. Exposes statusCode. |
SmsPartnersException |
Base class — also thrown for connection failures. |
Configuration
Custom base URL
If you are using a self-hosted or staging instance, pass a custom base URL as the second argument:
Testing
In your test suite, use Guzzle's MockHandler to intercept HTTP requests without hitting the real API: