PHP code example of taliffsss / unisms

1. Go to this page and download the library: Download taliffsss/unisms 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/ */

    

taliffsss / unisms example snippets


use Taliffsss\UniSms\UniSms;

$uniSms = new UniSms('your-secret-key');

$response = $uniSms->to('+639171234567')
    ->message('Hello world')
    ->from('MyBrand') // optional, defaults to "UniSMS"
    ->withMetadata(['order_id' => 12345]) // optional, echoed back by the API
    ->send();

// $response['message']['reference_id'], $response['message']['status'], ...

$status = $uniSms->get('msg_84e8b93b-6315-46af-a686');

use Taliffsss\UniSms\Exceptions\ApiException;
use Taliffsss\UniSms\Exceptions\TransportException;
use Taliffsss\UniSms\Exceptions\UniSmsException;

try {
    $uniSms->to('639171234567')->message('Hello world')->send();
} catch (ApiException $e) {
    // The API reached but returned a non-2xx response.
    $e->getStatusCode();
    $e->getResponseBody();
} catch (TransportException $e) {
    // The request could not be completed (network/timeout/etc.).
} catch (UniSmsException $e) {
    // Any other client-side validation error (e.g. missing recipient).
}