Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

send sms to users using free API

Laravel sends SMS to mobile

Today, I will give you an example of “How to Send SMS in Laravel (Send SMS to Mobile)”, So you can easily apply it with your laravel 5, laravel 6, laravel 7, laravel 8, and Laravel 9 application.

First, what we’re doing here, This is the example :

send SMS to users in Laravel

fast2sms API in Larvel

send free sms to user mobile laravel

Need to Send SMS to Mobile in Laravel

We need to send SMS to mobile whenever users login to our Laravel application we verify their phone numbers and also we use the SMS service to send notifications to users, for example: In the e-commerce platform for order status, order, and payment confirmation we use the SMS API to send a notification to users.

Step 1. Insert Some Dummy Records on the user’s table using Seeder

We have a default table user in our database just add a new column phone, Now create a seeder file.

Related article: Add a new column in the table using migration in Laravel.

Create a database Seeder

php artisan make:seeder UserTableSeeder



namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\User;

class UserTableSeeder extends Seeder
     * Run the database seeds.
     * @return void
    public function run()
        $users =[
            ['id'=>2,'name'=>'User 2','email'=>'','phone'=>'1212121212','password'=>'$2y$10$R']

Register Seeder

We Register UserTableSeeder Class in DatabaeSeeder File



namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
     * Seed the application's database.
     * @return void
    public function run()
        // \App\Models\User::factory(10)->create();

Hit the Seed Command

php artisan db:seed
user table seeder

Step 2. Create Controller and Model

php artisan make:controller SendSmsController
php artisan make:model Sms

Step 3. Create an account on the fast2sms website

fast2sms website url

We create an account on the fast2sms website, when you register on the fast2sms website you will get 50 rupee credits We test the message successfully.

Step 3. Send a Text Message Statically to test API

send text message using fast2ms api in Laravel

After successfully registration, just click on the Dev Api option to test a message service it’s all free just fill up all the details and click on Overall Url to send a message.

message send successfully

Step 4. Now we implement SMS API in Our Laravel application

setup environment in fast2sms API

Just fill-up the Dev API form and copy the authorization key and a sender ID. these are the credentials that we will use on our model to send SMS.

copy environment

Step 5. Define Web Route and Model



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\SendSmsController;

| 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!

// Send Sms to users Example
Route::get('/user-list', [SendSmsController::class, 'userlist'])->name('user.list');
Route::any('/send-sms-user/{id}', [SendSmsController::class, 'sendsmsTouser'])->name('sms.send');

Step 6. Setup API credentials and create a function in Sms Model

Create a function in the Sms model and paste your Sms API credentials.



namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Sms extends Model
    use HasFactory;

    public static function sendSms($message,$mobile){
    $request ="";

    foreach($param as $key => $val){
    $request =substr($request,0,strlen($request)-1);

    $url ="".$request;
    $ch =curl_init($url);


Step 7. Get all the records from the user table and send an SMS from the Controller



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use App\Models\Sms;

class SendSmsController extends Controller
    public function userlist(){
        $users = User::get();
        return view('sms.list',compact('users'));

    public function sendsmsTouser(Request $request,$id)
        $user = User::find($id);
        #send sms to user phone number
        $message = " ".$user->name.", Thank you for Registering in our Website.";
        $mobile = $user->phone;


<div class="container">
         <h3><a>Send Free Sms to User in Laravel using Fast2sms API.</a></h3>
         <table class="table">
               @foreach($users as $key => $user)
                  <th scope="row">{{ $key+1 }}</th>
                  <td>{{ $user->name }}</td>
                  <td>{{ $user->email }}</td>
                  <td>{{ $user->phone }}</td>
                  <td><a href="{{route('sms.send',$user->id)}}">Send Sms</a></td>

Step 8. Run your application and check the delivery report in fast2sms API and in your Mobile phone

Run Application :
send bulk sms to all users mobile laravel

delivery report after send sms

sms successfully received to user mobile laravel

In this article, we successfully learned “How to Send SMS to Mobile in Laravel”, I hope this article will help you with your Laravel application Project.

Read also: How to make Delete API in Laravel.