PHP SDK
Official PHP client for the Instasent Transactional API. Install via Composer, construct the SmsClient with your api_sms token, and call sendSms — Unicode, lookup and verify workflows are covered by separate clients in the same package.
The PHP SDK wraps SMS, lookup and verify into small focused clients. Most integrations only need SmsClient.
Installation
Via Composer
composer require instasent/instasent-php-libVia ZIP
Download the source from GitHub, drop the folder into your project and require the files directly:
require_once __DIR__ . '/path/to/lib/Abstracts/InstasentClient.php';
require_once __DIR__ . '/path/to/lib/SmsClient.php';Send an SMS
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Instasent\SmsClient(getenv('INSTASENT_TOKEN'));
$response = $client->sendSms('test', '+34647000000', 'test message');
echo $response['response_code'];
echo $response['response_body'];Unicode
For SMS containing characters outside GSM-7 (accents, emoji) use sendUnicodeSms:
$response = $client->sendUnicodeSms('test', '+34647000000', 'Unicode test: ña éáíóú 😀');Retrieve an SMS
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Instasent\SmsClient(getenv('INSTASENT_TOKEN'));
$response = $client->getSmsById('smsId');
echo $response['response_code'];
echo $response['response_body'];Lookup
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Instasent\LookupClient(getenv('INSTASENT_TOKEN'));
$response = $client->doLookup('+34666000000');
echo $response['response_code'];
echo $response['response_body'];Verify
Verify is a two-step workflow: request a code, then check it against the user input.
Request a code
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Instasent\VerifyClient(getenv('INSTASENT_TOKEN'));
$response = $client->requestVerify('test', '+34647000000', 'Your code is %token%', 6, 300);
echo $response['response_code'];
echo $response['response_body'];The fourth argument is the code length, the fifth is the validity in seconds.
Check the code
$client = new Instasent\VerifyClient(getenv('INSTASENT_TOKEN'));
$response = $client->checkVerify($requestVerifyId, $token);
$body = json_decode($response['response_body']);
if ($body->entity->status === 'verified') {
// success
} else {
// handle pending / failed / expired
}Requirements
PHP ≥ 5.2.3.
Getting help
For help installing or using the library, contact support@instasent.com. Bugs and feature requests belong on the GitHub repository.