Unlock SMS Sending in Laravel 7 with Nexmo

How to send SMS using Nexmo/Vonage Package in Laravel 

Send SMS Using Nexmo in Laravel 7

In this article we will learn how to send SMS using Nexmo in Laravel with example . Here will learn how to use Nexmo package , Nexmo package is now known as VONAGE . You can use this package for testing of your application , It provides you some limited amount of message for testing of your Application , After that you have to pay .

Let's see step by step how to use this package and send our first test sms .

Table of Content :

  • Register on Vonage
  • Get Your Code
  • Add Test Number
  • Create Route
  • Code in Controller

Step 1 - Register on Vonage :

First register on Vonage's Official site . Just fill the basic details and register on Vonage to use it's services .
After registration you will redirect to your dashboard like this .

Send SMS Using Nexmo in Laravel 7



Step 2 - Get your Code :

On the left side of your dashboard click on Getting Started under SMS section and select your programming language from the right side bar . Here i have selected PHP as i am using Laravel .

Just copy the entire code , so that we will use it in our controller .

Send SMS Using Nexmo in Laravel 7


Step 3 - Add Test Number :

To send Text SMS to any mobile number , fir you need to register that number on the vonage site and  it will send a verification message , after verification you can send message to that number .

On your profile section click on ' Test Numbers ' and add the number as shown below .

Send SMS Using Nexmo in Laravel 7

Step 4 - Create Route :

Create your route for accessing the controller .

Route::get('/sendsms','CheckController@sendSMS');

Step 5 - Code in Controller :

Just paste  the code you  have copied from the vonage site earlier on your controller method .

checkController.php :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class CheckController extends Controller
{
    public function sendSMS()
    {
        $basic  = new \Nexmo\Client\Credentials\Basic('fc14a005', 'Zhw4SFHQsObZgS5h');
        $client = new \Nexmo\Client($basic);

        $message = $client->message()->send([
            'to' => '91mobile number',
            'from' => 'Vonage APIs',
            'text' => 'test message from studywithkishan'
        ]);
        return 'message sent';
    }
}

That's it now run your route and check the recepient mobile you will get a message .\

Output :

Send SMS Using Nexmo in Laravel 7

On your Mobile :

Send SMS Using Nexmo in Laravel 7



Previous Post Next Post

Contact Form