PHP code example of headzoo / nexmo

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

    

headzoo / nexmo example snippets




use Headzoo\Nexmo\Sms;
use Headzoo\Nexmo\Exception\Exception;


// Start by creating an instance of Sms. You must have a Nexmo API key and secret, which you can find
// on the Nexmo dashboard. https://dashboard.nexmo.com/private/dashboard
// You also provide the "from" number or name. Each text you sent with the Sms instance will be sent
// from that number.
$nexmo_api_key = "n3xm0rocks";
$nexmo_api_secret = "12ab34cd";
$from = "12015555555";
$sms = Sms::factory($nexmo_api_key, $nexmo_api_secret, $from);


// To send a text message you pass the number you are sending to, in international format, along with
// the message to send. A Response instance is returned from which you can gather the details of the
// sent message. Keep in mind Nexmo may break up your text into several messages depending on
// the size of the sent message, and the Response will contain multiple Message instances.
try {
	$to = "19295555555";
	$message = "Hello, World!";
	$response = $sms->text($to, $message);
	foreach($response as $message) {
		echo "Message ID: " . $message->getId();
		echo "Message price: " . $message->getPrice();
		echo "Remaining balance: " . $message->getBalance();
	}
} catch (Exception $e) {
	echo $e->getMessage();
}
bash
# Install Composer
curl -sS https://getcomposer.org/installer | php