Download the PHP package moffhub/sms-handler without Composer

On this page you can find all versions of the php package moffhub/sms-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sms-handler

SMS Handler

Latest Version on Packagist Total Downloads

A simple, unified SMS integration library for Laravel. Send SMS messages through multiple providers with a consistent API, automatic fallback, rate limiting, templating, cost estimation, and analytics.

Features

Supported Providers

Installation

Configuration

Publish the config and migrations:

Environment Variables

Add the following to your .env file based on your provider:

Usage

Using the Facade

Using Dependency Injection

Switching Providers at Runtime

Fallback Provider Chain

Configure a fallback provider that is used automatically when the primary provider fails with a ProviderException. Fallback is limited to one level (no chaining beyond the fallback).

Or in config/sms.php:

When the primary provider fails, the package will:

  1. Log the failure
  2. Automatically retry with the fallback provider
  3. Log the fallback activation
  4. Return the fallback result (or null if the fallback also fails)

Non-ProviderException errors (e.g., validation errors) are not retried and are rethrown.

Rate Limiting

Configure per-provider rate limits (messages per minute). When the limit is exceeded, messages are automatically queued for later delivery instead of being rejected.

Or in config/sms.php:

Programmatic access:

Rate Limiting Recommendations

SMS Templating

Define reusable SMS templates with {{ variable }} interpolation:

Send a templated SMS:

Message length is validated after interpolation. If the rendered message exceeds the configured max_message_length, an InvalidMessageException is thrown.

Cost Estimation

Estimate the cost of sending an SMS before dispatching. The estimator calculates SMS segment count based on message encoding (GSM-7 vs UCS-2) and multiplies by the configured per-segment cost.

Segment Counting Rules

Encoding Single SMS Multi-part (per segment)
GSM-7 160 chars 153 chars
UCS-2 70 chars 67 chars

Unicode characters (emoji, CJK, Arabic, etc.) force UCS-2 encoding, which reduces the per-segment capacity.

Configure per-segment cost in your provider config:

When logging to the database (SMS_LOG_CHANNEL=model), the estimated_cost and segment_count columns are automatically populated on each SmsLog record.

Analytics & Success Rate Tracking

Query SMS analytics aggregated from the sms_logs table:

CLI Stats Command

View SMS statistics from the command line:

Error Handling

Exception Types

The package defines a hierarchy of exceptions:

Exception Description
SmsException Base exception class for all SMS errors
ProviderException Provider-level failures (API errors, timeouts). Triggers fallback if configured.
InvalidPhoneNumberException Invalid, empty, or malformed phone numbers
InvalidMessageException Empty or too-long messages

Handling Exceptions

Events

Listen for SMS lifecycle events:

Webhook Setup

Enable webhooks to receive delivery reports from providers:

This registers POST routes for each provider:

Provider Endpoint Route Name
Advanta POST /sms/webhooks/advanta sms.webhooks.advanta
Africa's Talking POST /sms/webhooks/africastalking sms.webhooks.africastalking
Onfon POST /sms/webhooks/onfon sms.webhooks.onfon
Nexmo POST /sms/webhooks/nexmo sms.webhooks.nexmo
Twilio POST /sms/webhooks/twilio sms.webhooks.twilio

Webhook Signature Validation

Set webhook secrets to validate incoming requests:

If a secret is configured, the package validates the signature header on incoming webhook requests. Invalid signatures receive a 403 response.

Provider Webhook Setup

Twilio:

  1. Go to your Twilio Console > Phone Numbers > Active Numbers
  2. Click your number and set the "A MESSAGE COMES IN" webhook URL to your endpoint
  3. Set the Status Callback URL to https://yourdomain.com/sms/webhooks/twilio

Africa's Talking:

  1. Go to your AT Dashboard > SMS > SMS Callback URLs
  2. Set the Delivery Reports URL to https://yourdomain.com/sms/webhooks/africastalking

Advanta:

  1. Configure the callback URL in your Advanta dashboard or pass it in the API request
  2. Set it to https://yourdomain.com/sms/webhooks/advanta

Nexmo/Vonage:

  1. Go to Vonage Dashboard > Settings
  2. Set the SMS Delivery Receipt URL to https://yourdomain.com/sms/webhooks/nexmo

Onfon:

  1. Contact Onfon support to configure your callback URL
  2. Set it to https://yourdomain.com/sms/webhooks/onfon

Delivery Report Payload Examples

Twilio:

Africa's Talking:

Advanta:

Nexmo/Vonage:

Onfon:

Africa's Talking Integration

The library fully supports the Africa's Talking Bulk SMS API:

Sandbox Testing

Production

Features

Custom Providers

Create your own provider by extending CustomProvider:

Register your provider:

Add config:

Update .env:

Laravel Notifications

Use SMS in Laravel notifications:

Ensure your notifiable model has a routeNotificationForSms method:

Logging

SMS messages can be logged to file or database:

When using database logging, each SmsLog record includes:

Structured Logging

The package logs structured events to a configurable log channel:

Log events include:

All log entries are scrubbed of sensitive data (API keys, tokens, secrets).

Testing & Mocking

Faking HTTP Requests

Use Laravel's HTTP faking to test SMS sending without making real API calls:

Faking Events

Test that events are dispatched correctly:

Testing Templates

Testing Cost Estimation

Troubleshooting

Common Issues

SMS not sending:

  1. Check your provider credentials in .env
  2. Verify SMS_PROVIDER is set to a valid provider name
  3. Check SMS_LOG_CHANNEL=log and review Laravel logs for errors
  4. Ensure your queue worker is running if using queued sending

Validation errors:

Rate limiting:

Webhooks not receiving reports:

Fallback not activating:

Cost estimation showing 0:

Debug Logging

Enable debug-level structured logging:

Testing

License

MIT License. See LICENSE for details.


All versions of sms-handler with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4|^8.5
laravel/framework Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package moffhub/sms-handler contains the following files

Loading the files please wait ...