alt-smsglobal/smsglobal-php

SMSGlobal PHP Client Library


Keywords
php, rest, api, library, sms, sdk, restapi, smsglobal
License
MIT

Documentation

SMSGlobal PHP Client Library

Build Coverage Latest Version Total Downloads

SMSGlobal REST API and Libraries for PHP

This is a PHP Client library for SMSGlobal’s REST API to integrate SMS capabilities into your PHP application.

Sign up for a free SMSGlobal account today and get your API Key from our advanced SMS platform, MXT. Plus, enjoy unlimited free developer sandbox testing to try out your API in full!

Requirements

  • PHP 7.2 and above
  • Guzzle6 (PHP HTTP client)

Installation

To install the PHP client library to your project, we recommend using Composer.

composer require smsglobal/smsglobal-php

Usage

Check out examples folder

Send SMS

<?php

require_once __DIR__ . '/vendor/autoload.php';

// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
\SMSGlobal\Credentials::set('YOUR_API_KEY', 'YOUR_SECRET_KEY');

$sms = new \SMSGlobal\Resource\Sms();

try {
    $response = $sms->sendToOne('DESTINATION_NUMBER', 'This is a test message.');
    print_r($response['messages']);
} catch (\Exception $e) {
    echo $e->getMessage();
}

Send OTP

<?php

require_once __DIR__ . '/vendor/autoload.php';

// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
\SMSGlobal\Credentials::set('YOUR_API_KEY', 'YOUR_SECRET_KEY');

$otp = new \SMSGlobal\Resource\Otp();

try {
    $response = $otp->send('DESTINATION_NUMBER', '{*code*} is your SMSGlobal verification code.');
    print_r($response);
} catch (\Exception $e) {
    echo $e->getMessage();
}

The following json response will be returned by the server:

{
    "requestId": "404372541683674336263499",
    "validUnitlTimestamp": "2020-11-18 16:24:51",
    "createdTimestamp": "2020-11-18 16:22:51",
    "lastEventTimestamp": "2020-11-18 16:22:51",
    "status": "Sent"
}

Verify OTP

Use requestId received from send request along with the OTP code enterted by your user

<?php

require_once __DIR__ . '/vendor/autoload.php';

// get your REST API keys from MXT https://mxt.smsglobal.com/integrations
\SMSGlobal\Credentials::set('YOUR_API_KEY', 'YOUR_SECRET_KEY');

$otp = new \SMSGlobal\Resource\Otp();

try {
    $response = $otp->verfiyById('request Id', 'OTP code enterted by your user.');
    print_r($response);
} catch (\Exception $e) {
    echo $e->getMessage();
}

Available REST API Resources

  • Sms
  • Sms Incoming
  • OTP
  • User

Unit Tests

Install development dependencies

composer require smsglobal/smsglobal-php

Run unit tests

./vendor/bin/phpunit tests

With coverage (requires extension pcov or xdebug)

./vendor/bin/phpunit --coverage-text tests

Getting help

View the REST API documentation for a list of available resources.

For any query contact us