Send SMS to Any Mobile Number Using Laravel 12 – Step-by-Step Guide
Sending SMS is an essential feature for many applications — whether it’s an eCommerce store, education platform, or customer service system. SMS allows you to send OTP codes, promotional offers, or subscription messages directly to your users’ phones.
In this tutorial, we’ll learn how to send SMS in Laravel 12 step by step. We’ll build a simple SMS form and integrate it with a third-party SMS API.
Here are the steps to do this:
Step 1: Install Laravel Project
If you don’t have a Laravel project yet, create one using Composer:
composer create-project laravel/laravel sms-send
Step 2: Create Routes
Add routes for the SMS form and sending messages in routes/web.php
:
use App\Http\Controllers\SmsController;
Route::get('/sms-form', [SmsController::class, 'sms_form'])->name('sms.form');
Route::post('/sms-send', [SmsController::class, 'sms_send'])->name('sms.send');
Step 3: Create Blade View (SMS Form)
Create a simple form to collect the phone number and message:
resources/views/sms-form.blade.php
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<title>Send SMS in Laravel 12</title>
</head>
<body>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-lg-6">
<h2 class="mb-4">Send SMS with Laravel 12</h2>
<form action="{{ route('sms.send') }}" method="POST">
@csrf
<div class="mb-3">
<label for="phone" class="form-label">Phone Number</label>
<input type="text" class="form-control" name="phone" id="phone" required>
</div>
<div class="mb-3">
<label for="message" class="form-label">Message</label>
<input type="text" class="form-control" name="message" id="message" required>
</div>
<button type="submit" class="btn btn-primary">Send SMS</button>
</form>
</div>
</div>
</div>
</body>
</html>
Step 4: Create SMS Controller
php artisan make:controller SmsController
Then update it like this:
app/Http/Controllers/SmsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SmsController extends Controller
{
public function sms_form()
{
return view('sms-form');
}
public function sms_send(Request $request)
{
$phone = $request->phone;
$message = $request->message;
// Use your third-party SMS API here (example: BD Bulk SMS)
$url = "https://api.bdbulksms.net/api.php?json";
$token = "your_valid_api_token"; // Replace with your real token
$data = [
'to' => $phone,
'message' => $message,
'token' => $token
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
return back()->with('success', 'SMS sent successfully!');
}
}
Step 5: Use a Third-Party SMS API
To send SMS in Laravel, you need to sign up with an SMS provider such as:
-
Nexmo (Vonage)
Each provider gives you an API key/token which you must replace in the controller.
Now your Laravel 12 application can send SMS messages to any phone number!
With this setup, you can:
-
Send OTP SMS for login/signup
-
Send Promotional SMS to customers
-
Send Transactional notifications
-
Send Order sms
You May Also Like Bellow Articles:
Laravel live search data in a table using ajax.
How to send SMS in laravel using Twilio SMS API-Webjourney
Laravel pdf invoice generate and download with barryvdh dompdf
How to create multi language website by laravel
Laravel 11 multiple form validation on the same page-WebJourney
Laravel 10,11 Breeze Authentication - WebJourney
Laravel 11 Ajax jQuery Crud with Pagination and Live Search
Laravel Naming Conventions Accepted by Laravel community
Laravel Shorter and More Readable Syntax - WebJourney