1. Go to this page and download the library: Download calisero/calisero-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/ */
alisero\Sms\SmsClient;
use Calisero\Sms\Dto\CreateMessageRequest;
use Calisero\Sms\Exceptions\NotFoundException;
$client = SmsClient::create('your-api-key-here');
// Check if user is opted out first
try {
$client->optOuts()->get($phoneNumber);
echo "User is opted out, skipping message\n";
} catch (NotFoundException $e) {
// User is not opted out, safe to send
$request = new CreateMessageRequest(
recipient: $phoneNumber,
body: "Special offer! Get 20% off with code SAVE20. Reply STOP to opt out.",
sender: 'YourBrand'
);
$response = $client->messages()->create($request);
echo "Marketing message sent!\n";
}
alisero\Sms\SmsClient;
use Calisero\Sms\Dto\CreateMessageRequest;
$client = SmsClient::create('your-api-key-here');
$request = new CreateMessageRequest(
recipient: '+40742***350',
body: 'Your code is 123456. Manage alerts: https://yoursite.com/alerts',
visibleBody: 'Your code is ******. Manage alerts: https://yoursite.com/alerts', // For logs/display
validity: 24, // 24 hours validity
scheduleAt: '2024-12-25 10:00:00', // Schedule for later
callbackUrl: 'https://yoursite.com/webhook', // Delivery reports
sender: 'Calisero', // Custom sender
shortenUrls: true // Shorten the links of the body
);
$response = $client->messages()->create($request);
echo "Advanced message created with ID: " . $response->getData()->getId() . "\n";
alisero\Sms\Contracts\AuthProviderInterface;
class CustomAuthProvider implements AuthProviderInterface
{
public function getToken(): string
{
// Your custom token logic here
return $this->fetchTokenFromSomewhere();
}
}
$bearerToken = 'your-api-key-here'; // Replace with your actual API key
alisero\Sms\SmsClient;
use Calisero\Sms\Dto\CreateMessageRequest;
$client = SmsClient::create('your-api-key-here');
$request = new CreateMessageRequest(
recipient: '+40742***350',
body: 'Hello World!'
);
$response = $client->messages()->create($request);
$message = $response->getData();
echo $message->getId(); // Message UUID
echo $message->getStatus(); // Message status
echo $message->getParts(); // Number of SMS parts
// What the answer's headers report
$meta = $response->getResponseMeta();
echo $meta->getTraceId(); // The request's trace ID
echo $meta->getDailyRemaining(); // Messages left today (null: no daily limit)
alisero\Sms\SmsClient;
use Calisero\Sms\Dto\CreateMessageRequest;
$client = SmsClient::create('your-api-key-here');
$request = new CreateMessageRequest(
recipient: '+40742***350',
body: 'Your order has shipped! Track it: https://yourstore.com/orders/12345/tracking',
shortenUrls: true
);
$message = $client->messages()->create($request)->getData();
foreach ($message->getShortenedUrls() as $link) {
echo $link->getOriginalLink(); // https://yourstore.com/orders/12345/tracking
echo $link->getShortenedLink(); // https://calisero.ro/s/ghJKPV
}
// Later: how many times the link was opened
$message = $client->messages()->get($message->getId())->getData();
foreach ($message->getShortenedUrls() as $link) {
echo $link->getClickCount(); // Number of clicks
echo $link->getLastClick(); // Last click timestamp, or null
}
alisero\Sms\Dto\DeliveryWebhookMessage;
try {
$webhook = DeliveryWebhookMessage::fromJson((string) file_get_contents('php://input'));
} catch (InvalidArgumentException $e) {
http_response_code(400); // Malformed payload
exit;
}
echo $webhook->getMessageId(); // The message's UUID
echo $webhook->getStatus(); // 'sent', 'delivered' or 'undelivered'
echo $webhook->getDeliveredAt(); // Set for 'delivered'
echo $webhook->getPrice(); // Price charged for the message's parts
echo $webhook->getRemainingBalance(); // Account balance after billing
echo $webhook->getDailyRemaining(); // Messages left today when it was sent (null: no daily limit)
// Answer with any 2xx within 2 seconds
http_response_code(200);
echo '{"received":true}';
alisero\Sms\SmsClient;
use Calisero\Sms\Dto\CreateMessageRequest;
$client = SmsClient::create('your-api-key-here');
// 1. On the account
$account = $client->accounts()->get('account-uuid-here')->getData();
echo $account->getDailyLimit(); // e.g. 1000, or null when no daily limit applies
echo $account->getDailyRemaining(); // e.g. 873
echo $account->getSentToday(); // e.g. 127
// 2. After every message or verification created (X-Daily-Limit / X-Daily-Remaining)
$response = $client->messages()->create(new CreateMessageRequest(
recipient: '+40742***350',
body: 'Hello!'
));
echo $response->getResponseMeta()->getDailyLimit(); // e.g. 1000
echo $response->getResponseMeta()->getDailyRemaining(); // e.g. 872, after this message
// 3. In every delivery status callback: DeliveryWebhookMessage::getDailyRemaining()
use Calisero\Sms\Exceptions\DailyLimitExceededException;
try {
$client->messages()->create($request);
} catch (DailyLimitExceededException $e) {
echo $e->getMessage(); // What happened and when the limit resets
echo $e->getDailyLimit(); // e.g. 1000
echo $e->getDailyRemaining(); // 0
echo $e->getResetsAt(); // e.g. 2026-10-01T00:00:00+03:00
echo $e->getRetryAfter(); // Seconds until the reset
}
use Calisero\Sms\Exceptions\DailyLimitExceededException;
use Calisero\Sms\Exceptions\RateLimitedException;
try {
$client->messages()->create($request);
} catch (DailyLimitExceededException $e) {
// The daily sending limit: wait until $e->getResetsAt()
} catch (RateLimitedException $e) {
// The request rate limit: wait a few seconds and retry
sleep($e->getRetryAfter() ?? 1);
echo $e->getRateLimitLimit(); // 240
echo $e->getRateLimitRemaining(); // 0
echo $e->getRateLimitReset(); // Unix timestamp when requests are accepted again
}
use Calisero\Sms\Exceptions\ApiException;
// On success
echo $client->messages()->create($request)->getResponseMeta()->getTraceId();
// On error
try {
$client->messages()->create($request);
} catch (ApiException $e) {
error_log('Calisero request ' . $e->getTraceId() . ' failed: ' . $e->getMessage());
}
alisero\Sms\SmsClient;
// Simple client creation - all you need
$client = SmsClient::create('your-api-key-here');
alisero\Sms\Auth\BearerTokenAuthProvider;
use Calisero\Sms\Dto\CreateMessageRequest;
use Calisero\Sms\Http\BaseHttpClient;
use Calisero\Sms\Http\Factory\HttpFactory;
use Calisero\Sms\Http\HttpClient;
use Calisero\Sms\IdempotencyKey\UuidIdempotencyKeyProvider;
use Calisero\Sms\Services\AccountService;
use Calisero\Sms\Services\MessageService;
use Calisero\Sms\Services\OptOutService;
use Calisero\Sms\Services\VerificationService;
$httpClient = new HttpClient(
new BaseHttpClient(60, 5), // Timeout and connect timeout, in seconds
new HttpFactory(),
new BearerTokenAuthProvider('your-api-key-here'), // Or your own AuthProviderInterface
'https://rest.calisero.ro/api/v1',
new UuidIdempotencyKeyProvider() // Or your own IdempotencyKeyProviderInterface
);
// The same services SmsClient returns from messages(), verifications(), optOuts() and accounts()
$messages = new MessageService($httpClient);
$verifications = new VerificationService($httpClient);
$optOuts = new OptOutService($httpClient);
$accounts = new AccountService($httpClient);
$messages->create(new CreateMessageRequest(
recipient: '+40742***350',
body: 'Hello!'
));
$account = $accounts->get('account-uuid-here')->getData();
// The raw response to the last request, headers
alisero\Sms\Auth\BearerTokenAuthProvider;
use Calisero\Sms\Contracts\IdempotencyKeyProviderInterface;
use Calisero\Sms\Http\BaseHttpClient;
use Calisero\Sms\Http\Factory\HttpFactory;
use Calisero\Sms\Http\HttpClient;
use Calisero\Sms\Services\MessageService;
class CustomIdempotencyProvider implements IdempotencyKeyProviderInterface
{
public function generate(): string
{
return 'custom-' . uniqid() . '-' . time();
}
}
$httpClient = new HttpClient(
new BaseHttpClient(30, 10),
new HttpFactory(),
new BearerTokenAuthProvider('your-api-key-here'),
'https://rest.calisero.ro/api/v1',
new CustomIdempotencyProvider()
);
$messages = new MessageService($httpClient);
use Calisero\Sms\Dto\CreateMessageRequest;
use Calisero\Sms\Http\HttpClient;
use Calisero\Sms\Services\MessageService;
use PHPUnit\Framework\TestCase;
class YourSmsTest extends TestCase
{
public function testSendMessage(): void
{
$httpClient = $this->createMock(HttpClient::class);
$httpClient->expects($this->once())
->method('post')
->with('/messages', ['recipient' => '+40742***350', 'body' => 'Hello!'], true)
->willReturn([
'data' => [
'id' => '9e2574e8-3615-4090-9b5a-0fc812079da8',
'recipient' => '+40742***350',
'body' => 'Hello!',
'parts' => 1,
'created_at' => '2025-02-06T10:18:43.000000Z',
'status' => 'scheduled',
],
]);
$messages = new MessageService($httpClient);
$message = $messages->create(new CreateMessageRequest('+40742***350', 'Hello!'))->getData();
$this->assertSame('scheduled', $message->getStatus());
}
}
bash
composer
bash
git clone https://github.com/calisero/calisero-php.git
cd calisero-php
composer install
bash
php examples/messages/send_simple_sms.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.