By Hardik Savani February 17, 2021 Category : LaravelPlayUnmuteLoaded: 1.17%FullscreenHi,
This tutorial shows you laravel send sms to mobile with nexmo. i would like to share with you how to send sms using nexmo in laravel. This article will give you simple example of send sms using nexmo in laravel. step by step explain laravel sms notification nexmo. You just need to some step to done laravel nexmo message.
In this example, i will give you very simple example to sending sms using nexmo/vonage api in laravel app. you can easily use this code in laravel 6, laravel 7, laravel 8 and laravel 9 app.
let's follow bellow steps:
Step 1: Install Laravel
first of all we need to get fresh Laravel version application using bellow command, So open your terminal OR command prompt and run bellow command:
composer create-project --prefer-dist laravel/laravel blog
Step 2: Create Nexmo Account
First you need to create account on nexmo. then you can easily get client id and secret.
<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\NexmoSMSController; /*|--------------------------------------------------------------------------| Web Routes|--------------------------------------------------------------------------|| Here is where you can register web routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| contains the "web" middleware group. Now create something great!|*/ Route::get('sendSMS', [NexmoSMSController::class, 'index']);
<?php namespace App\Http\Controllers; use Illuminate\Http\Request;use Exception; class NexmoSMSController extends Controller{ /** * Write code on Method * * @return response() */ public function index() { try { $basic = new \Nexmo\Client\Credentials\Basic(getenv("NEXMO_KEY"), getenv("NEXMO_SECRET")); $client = new \Nexmo\Client($basic); $receiverNumber = "91846XXXXX"; $message = "This is testing from ItSolutionStuff.com"; $message = $client->message()->send([ 'to' => $receiverNumber, 'from' => 'Vonage APIs', 'text' => $message ]); dd('SMS Sent Successfully.'); } catch (Exception $e) { dd("Error: ". $e->getMessage()); } }}