PHPackages                             parvion/laravel-msg91 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. parvion/laravel-msg91

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

parvion/laravel-msg91
=====================

A robust Laravel wrapper for MSG91 (v5) supporting OTP, SMS, Email, and WhatsApp with full database logging.

12PHPCI failing

Since May 27Pushed 1mo agoCompare

[ Source](https://github.com/AnandKumar2002/laravel-msg91)[ Packagist](https://packagist.org/packages/parvion/laravel-msg91)[ RSS](/packages/parvion-laravel-msg91/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel MSG91 Integration
=========================

[](#laravel-msg91-integration)

A robust, enterprise-grade, API-first Laravel wrapper for MSG91 (v5). This package is strictly designed for API-driven architectures (like headless CMSs), providing comprehensive coverage of MSG91's OTP, SMS, Email, and WhatsApp endpoints without the bloat of frontend UI components. Supports **Laravel 10, 11, 12, and 13** with **PHP 8.1+**.

---

📑 Table of Contents
-------------------

[](#-table-of-contents)

1. [🚀 Installation](#-installation)
2. [⚙️ Configuration &amp; Logging](#%EF%B8%8F-configuration--logging)
3. [☎️ Phone Number Formatting](#%EF%B8%8F-phone-number-formatting)
4. [📱 OTP Features](#-otp-features)
    - [Send an OTP](#send-an-otp)
    - [Verify an OTP](#verify-an-otp)
    - [Resend &amp; Retry (Voice/Text)](#resend--retry)
    - [Smart Fallback](#smart-fallback)
    - [Analytics &amp; Logs](#otp-analytics--logs)
5. [✉️ SMS Features](#%EF%B8%8F-sms-features)
    - [Send a Single SMS](#send-a-single-sms)
    - [Send Bulk SMS](#send-bulk-sms)
    - [Background Queue Jobs](#dispatch-background-job-highly-recommended)
    - [Schedule SMS](#schedule-sms-for-the-future)
    - [Trigger Campaign Flow](#trigger-msg91-campaign-flow)
    - [Check Delivery &amp; Analytics](#sms-delivery-status--analytics)
6. [📧 Email Features](#-email-features)
    - [Send a Single Email](#send-a-single-email)
    - [Send Bulk Email](#send-bulk-email)
    - [Strict Validation](#email-with-strict-validation)
    - [Send via CSV Upload](#massive-csv-bulk-send)
    - [Programmatic Templates](#create--fetch-templates)
    - [Email Logs](#email-logs)
7. [🟢 WhatsApp Features](#-whatsapp-features)
    - [Standard Text Message](#send-a-standard-whatsapp-message)
    - [Template Messages](#send-an-approved-whatsapp-template)
8. [🪝 Webhooks (DLR)](#-webhooks-delivery-receipts---dlr)
9. [🧪 Testing (Fakes)](#-testing)

---

🚀 Installation
--------------

[](#-installation)

Install the package via composer:

```
composer require parvion/laravel-msg91
```

Publish the configuration file (optional, but highly recommended):

```
php artisan vendor:publish --tag="msg91-config"
```

Publish the database migration for Activity Logging (Optional):

```
php artisan vendor:publish --tag="msg91-migrations"
php artisan migrate
```

---

⚙️ Configuration &amp; Logging
------------------------------

[](#️-configuration--logging)

The package is designed to be entirely driven by your `.env` file. You don't need to pass templates or sender IDs in your code if you configure them here:

```
# Core Settings
MSG91_AUTH_KEY="your-real-msg91-auth-key"
MSG91_SENDER_ID="YOURID"
MSG91_COUNTRY_CODE="91"

# Feature Toggles (Turn off channels you don't use to save memory)
MSG91_FEATURE_OTP=true
MSG91_FEATURE_SMS=true
MSG91_FEATURE_EMAIL=true
MSG91_FEATURE_WHATSAPP=true

# Logging (Database & File)
MSG91_LOG_DRIVER="database" # Options: null, log, database, stack

# Granular Logging Control (Only log the channels you want!)
MSG91_LOG_OTP=true
MSG91_LOG_SMS=false     # Disable SMS logs to save database space
MSG91_LOG_EMAIL=true
MSG91_LOG_WHATSAPP=true
```

---

☎️ Phone Number Formatting
--------------------------

[](#️-phone-number-formatting)

MSG91 requires numbers to include the country code (e.g., `919876543210` for India).

However, **you can pass either 10-digit or 12-digit numbers to this package.**The built-in formatter automatically checks your `MSG91_COUNTRY_CODE` setting:

- Pass 10 digits (`9876543210`) -&gt; Auto-prepends country code (`919876543210`).
- Pass 12 digits or plus sign (`+919876543210`) -&gt; Formatted correctly for the API (`919876543210`).

---

📱 OTP Features
--------------

[](#-otp-features)

### Send an OTP

[](#send-an-otp)

```
use Parvion\Msg91\Facades\Msg91;
use Parvion\Msg91\DTOs\OtpData;

$response = Msg91::sendOtp(OtpData::fromArray([
    'mobile' => '919876543210',
    // 'template_id' => '...' (Optional: automatically pulls from config)
]));
```

### Verify an OTP

[](#verify-an-otp)

```
// Returns the MSG91 array on success, throws an InvalidOtpException on failure
use Parvion\Msg91\Exceptions\InvalidOtpException;

try {
    Msg91::verifyOtp('919876543210', '123456');
} catch (InvalidOtpException $e) {
    if ($e->isExpired()) {
        // Tell frontend to show "Resend" button
    } elseif ($e->isIncorrect()) {
        // Tell frontend "Wrong code"
    }
}
```

### Resend &amp; Retry

[](#resend--retry)

```
// Standard text resend
Msg91::resendOtp('919876543210');

// Retry via Voice Call (Perfect for users who didn't receive the text)
use Parvion\Msg91\Enums\OtpRetryType;
Msg91::retryOtp('919876543210', OtpRetryType::Voice);
```

### Smart Fallback

[](#smart-fallback)

```
// Attempts SMS, if fails tries WhatsApp, then finally Email automatically!
Msg91::fallbackOtp('919876543210', ['sms', 'whatsapp', 'email']);
```

### OTP Analytics &amp; Logs

[](#otp-analytics--logs)

```
$analytics = Msg91::getOtpAnalytics(now()->subMonth(), now());
$logs      = Msg91::getOtpLogs(now()->subDays(7), now());
```

---

✉️ SMS Features
---------------

[](#️-sms-features)

### Send a Single SMS

[](#send-a-single-sms)

```
use Parvion\Msg91\DTOs\SmsData;
use Parvion\Msg91\Enums\SmsRoute;

Msg91::sendSms(SmsData::fromArray([
    'mobile'  => '919876543210',
    'message' => 'Your order #12345 is confirmed!',
    'route'   => SmsRoute::Transactional,
]));
```

### Send Bulk SMS

[](#send-bulk-sms)

```
$recipients = ['919876543210', '919876543211', '919876543212'];

Msg91::sendBulkSms($recipients, SmsData::fromArray([
    'message' => 'HUGE SALE! Everything 50% off today only!',
    'route'   => SmsRoute::Promotional,
]));
```

### Dispatch Background Job (Highly Recommended)

[](#dispatch-background-job-highly-recommended)

Never make your users wait for an HTTP request to finish.

```
use Parvion\Msg91\Jobs\SendSmsJob;

// Queues the SMS to be sent by a background worker instantly.
SendSmsJob::dispatch(SmsData::fromArray([
    'mobile'  => '919876543210',
    'message' => 'Your order is confirmed!',
]));
```

### Schedule SMS for the Future

[](#schedule-sms-for-the-future)

```
// Sends exactly 2 days from now
Msg91::scheduleSms($smsData, now()->addDays(2));
```

### Trigger MSG91 Campaign Flow

[](#trigger-msg91-campaign-flow)

```
// Trigger a visual Flow built in your MSG91 dashboard
Msg91::triggerFlow('flow_id_abc123', ['customer_name' => 'John Doe'], '919876543210');
```

### SMS Delivery Status &amp; Analytics

[](#sms-delivery-status--analytics)

```
$status    = Msg91::checkDeliveryStatus('msg91-request-id-12345');
$analytics = Msg91::getSmsAnalytics(now()->subMonth(), now());
```

---

📧 Email Features
----------------

[](#-email-features)

### Send a Single Email

[](#send-a-single-email)

```
use Parvion\Msg91\DTOs\EmailData;

Msg91::sendEmail(EmailData::fromArray([
    'to'         => ['john@example.com'],
    'subject'    => 'Welcome to the platform!',
    'template_id'=> 'your-email-template-id',
    'variables'  => ['name' => 'John'], // Dynamic template injection
]));
```

### Send Bulk Email

[](#send-bulk-email)

```
$emails = ['user1@example.com', 'user2@example.com', 'user3@example.com'];

Msg91::sendBulkEmail($emails, EmailData::fromArray([
    'subject'    => 'System Maintenance Notice',
    'template_id'=> 'maintenance-template-id',
]));
```

### Email with Strict Validation

[](#email-with-strict-validation)

```
// Enforces strict deliverability validation on the MSG91 side
Msg91::sendEmailWithValidation($emailData);
```

### Massive CSV Bulk Send

[](#massive-csv-bulk-send)

```
// Send thousands of emails instantly by uploading a CSV
Msg91::sendEmailWithCsv(storage_path('app/contacts.csv'), $emailData);
```

### Create &amp; Fetch Templates

[](#create--fetch-templates)

```
// Create a new HTML template programmatically
Msg91::createEmailTemplate('Monthly Newsletter', 'Hello World');

// Fetch all existing templates
$templates = Msg91::getEmailTemplates(['per_page' => 50]);
```

### Email Logs

[](#email-logs)

```
$logs = Msg91::getEmailLogs(now()->subWeek(), now());
```

---

🟢 WhatsApp Features
-------------------

[](#-whatsapp-features)

### Send a Standard WhatsApp Message

[](#send-a-standard-whatsapp-message)

```
use Parvion\Msg91\DTOs\WhatsAppData;

Msg91::sendWhatsApp(WhatsAppData::fromArray([
    'mobile'  => '919876543210',
    'message' => 'Hello from WhatsApp!',
]));
```

### Send an Approved WhatsApp Template

[](#send-an-approved-whatsapp-template)

```
Msg91::sendWhatsAppTemplate(WhatsAppData::fromArray([
    'mobile'      => '919876543210',
    'template_id' => 'your_approved_whatsapp_template_id',
    'variables'   => ['name' => 'John'],
]));
```

---

🪝 Webhooks (Delivery Receipts - DLR)
------------------------------------

[](#-webhooks-delivery-receipts---dlr)

Instead of polling MSG91 to see if an SMS or OTP was delivered, let MSG91 tell your application automatically.

**1. Register the route** in your `routes/api.php`:

```
use Parvion\Msg91\Http\Controllers\Msg91WebhookController;

Route::post('/msg91/webhook', [Msg91WebhookController::class, 'handle']);
```

**2. Listen for the Laravel Events:**When MSG91 pings your webhook, the package will dispatch native events. Create an Event Listener in your app to handle them:

```
namespace App\Listeners;

use Parvion\Msg91\Events\MessageDeliveryStatusChanged;

class UpdateMessageStatus
{
    public function handle(MessageDeliveryStatusChanged $event)
    {
        // $event->requestId
        // $event->status ('delivered', 'failed', 'sent')
        // $event->rawPayload (The full JSON from MSG91)

        // Example: DB::table('messages')->where('request_id', $event->requestId)->update(['status' => $event->status]);
    }
}
```

---

🧪 Testing
---------

[](#-testing)

The package provides a built-in `Msg91Fake` for flawless TDD. You will never accidentally spend money or hit real API limits while testing.

```
use Parvion\Msg91\Facades\Msg91;

public function test_user_registration_sends_otp()
{
    // 1. Swap the real API with our in-memory Fake
    Msg91::fake();

    // 2. Trigger your application logic
    $this->postJson('/api/register', ['phone' => '919876543210']);

    // 3. Assert the exact API call was made!
    Msg91::assertOtpSent('919876543210');
    Msg91::assertSmsNotSent();
    Msg91::assertEmailNotSent();
}
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

20

—

LowBetter than 12% of packages

Maintenance58

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b84ce931c7243cd3a15fdb641abf1443a66fd4635b68470eed5df38d99d20359?d=identicon)[AnandKumar2002](/maintainers/AnandKumar2002)

---

Top Contributors

[![AnandKumar2002](https://avatars.githubusercontent.com/u/139989819?v=4)](https://github.com/AnandKumar2002 "AnandKumar2002 (8 commits)")

### Embed Badge

![Health badge](/badges/parvion-laravel-msg91/health.svg)

```
[![Health](https://phpackages.com/badges/parvion-laravel-msg91/health.svg)](https://phpackages.com/packages/parvion-laravel-msg91)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
