This example shows you how to send an SMS to your chosen number.

First, sign up for a Vonage account if you don't already have one, and make a note of your API key and secret on the dashboard getting started page.


Install dependencies

open command window and download nexmo vonage dependencies via composer command

composer require vonage/client

Once you have installed library the copy the following code and replace the following placeholder values in the sample code:


#index.php

<?php

require_once __DIR__ . 'vendor/autoload.php';

$basic  = new \Vonage\Client\Credentials\Basic(VONAGE_API_KEY, VONAGE_API_SECRET);
$client = new \Vonage\Client($basic);

$response = $client->sms()->send(
    new \Vonage\SMS\Message\SMS(TO_NUMBER, BRAND_NAME, 'A text message sent using the Nexmo SMS API')
);

$message = $response->current();

if ($message->getStatus() == 0) {
    echo "The message was sent successfully\n";
} else {
    echo "The message failed with status: " . $message->getStatus() . "\n";
}

Run the following code it will send SMS easy