1. Go to this page and download the library: Download smscx/smscx-api-php-library 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/ */
smscx / smscx-api-php-library example snippets
ig = Smscx\Configuration::getDefaultConfiguration()
->setApplicationId('YOUR_APPLICATION_ID')
->setApplicationSecret('YOUR_APPLICATION_SECRET');
$smscx = new Smscx\Api\OauthApi(
new GuzzleHttp\Client(),
$config
);
// A list of space-delimited, case-sensitive strings. If left empty or ommited,
// the issued access token will be granted with all scopes (full privileges)
$scopes = '';
try {
$result = $smscx->getAccessToken($scopes);
$accessToken = $result->getAccessToken();
$expiresIn = $result->getExpiresIn();
print_r($result);
} catch (Smscx\Client\Exception\InvalidRequestException $e) {
//Code for Invalid request
} catch (Smscx\Client\Exception\InvalidCredentialsException $e) {
//Code for Invalid credentials
} catch (Smscx\Client\Exception\InvalidScopeException $e) {
//Code for Invalid scope
} catch (Smscx\Client\Exception\ApiException $e) {
echo 'Exception when calling OauthApi->getAccessToken: ', $e->getMessage(), PHP_EOL;
}
e authentication via API Key
$config = Smscx\Configuration::getDefaultConfiguration()->setApiKey('YOUR_API_KEY');
// OR
// Use authentication via Access Token
// $config = Smscx\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$smscx = new Smscx\Api\SmsApi(
new GuzzleHttp\Client(),
$config
);
$send_sms_message_request = [
'to' => '+31612469xxx',
'from' => 'InfoText',
'text' => 'Your confirmation code is 15997',
];
try {
$result = $smscx->sendSms($send_sms_message_request);
print_r($result);
//$result->getInfo()->getTotalCost();
} catch (InvalidArgumentException $e) {
//Code for Invalid argument provided
} catch (Smscx\Client\Exception\NoCoverageException $e) {
//Code for No coverage
} catch (Smscx\Client\Exception\InvalidRequestException $e) {
//Code for Invalid request
} catch (Smscx\Client\Exception\InvalidPhoneNumberException $e) {
//Code for Invalid phone number
} catch (Smscx\Client\Exception\InsufficientBalanceException $e) {
//Code for Insufficient balance
} catch (Smscx\Client\Exception\ApiException $e) {
echo 'Exception when calling SmsApi->sendSms: ', $e->getMessage(), PHP_EOL;
// $http_code = $e->getCode(); # For HTTP response code: 400, 401, 403, 429, 500, etc
// $error_type = $e->getResponseObject()->getError()->getType(); # For type of error: invalid_param, insufficient_credit, rate_limit, etc
// $error_message = $e->getResponseObject()->getError()->getMessage(); # Short description of the error
// $error_code = $e->getResponseObject()->getError()->getCode(); # API internal error code: 1208, 1101, 1221, etc
}
e authentication via API Key
$config = Smscx\Configuration::getDefaultConfiguration()->setApiKey('YOUR_API_KEY');
// OR
// Use authentication via Access Token
// $config = Smscx\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$smscx = new Smscx\Api\SmsApi(
new GuzzleHttp\Client(),
$config
);
$send_sms_message_request = [
//Max 25.000 phone numbers
'to' => [
'+31612469xxx',
'+4474005085xx',
'+49151238353xx',
'+417811126xx',
'+3519123350xx',
'+4206016090xx',
'+359483059xx',
'+336127904xx',
'+436645595xx',
'+3519121385xx',
'+3069125917xx',
],
'from' => 'InfoText',
'text' => 'Redeem this voucher and you will get 30% discount off all Summer Fashion {{optoutLink}}',
'allowInvalid' => true,
'transliteration' => [
'alphabet' => 'NON_GSM',
'removeEmojis' => true,
],
'idempotencyId' => '854cd53f-d77d-4aa8-9bd9-fbf720f3332d',
];
try {
$result = $smscx->sendSms($send_sms_message_request);
print_r($result);
//$result->getInfo()->getTotalCost();
//$result->getInfo()->getInvalid();
} catch (InvalidArgumentException $e) {
//Code for Invalid argument provided
} catch (Smscx\Client\Exception\NoCoverageException $e) {
//Code for No coverage
} catch (Smscx\Client\Exception\InvalidRequestException $e) {
//Code for Invalid request
} catch (Smscx\Client\Exception\InvalidPhoneNumberException $e) {
//Code for Invalid phone number
} catch (Smscx\Client\Exception\InsufficientBalanceException $e) {
//Code for Insufficient balance
} catch (Smscx\Client\Exception\ApiException $e) {
echo 'Exception when calling SmsApi->sendSms: ', $e->getMessage(), PHP_EOL;
// $http_code = $e->getCode(); # For HTTP response code: 400, 401, 403, 429, 500, etc
// $error_type = $e->getResponseObject()->getError()->getType(); # For type of error: invalid_param, insufficient_credit, rate_limit, etc
// $error_message = $e->getResponseObject()->getError()->getMessage(); # Short description of the error
// $error_code = $e->getResponseObject()->getError()->getCode(); # API internal error code: 1208, 1101, 1221, etc
}
try {
// Method
} catch (Smscx\Client\Exception\InvalidRequestException $e) {
// Code for this situation
} catch (Smscx\Client\Exception\RateLimitExcedeedException $e) {
// Wait some time and retry the request
$retryAfter = $e->getHeader('X-Rate-Limit-Reset'); //Unix timestamp eg. 1664103086
} catch (Smscx\Client\Exception\ServerErrorException $e) {
// Code for this situation
} catch (Smscx\Client\Exception\ApiException $e) {
// If you want to analyze the Error object
$httpCode = $e->getCode();
$errorType = $e->getResponseObject()->getError()->getType();
$errorMessage = $e->getResponseObject()->getError()->getMessage();
$errorCode = $e->getResponseObject()->getError()->getCode();
}