PHP code example of 2amigos / yii2-nexmo-library

1. Go to this page and download the library: Download 2amigos/yii2-nexmo-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/ */

    

2amigos / yii2-nexmo-library example snippets


// to send an sms message
$sms = new \dosamigos\nexmo\Sms(['key' => 'API_KEY', 'secret' => 'API_SECRET', 'from' => 'SENDERID']);

// lets call the API to get a json response
$sms->format = 'json';

// send a message with an optional parameter (see Nexmo doc for more optional parameters)
$response = $sms->sendText('RECIPIENTSNUMBER', 'Hello World!', ['clientRef' => 'YOURCLIENTREF']);

// if a response expects a JSON object, it will return as an array, if format was a XML, it will return an object.
echo $response['message-count']; // the number of parts the message was split into