PHPackages                             spiderhit/smsapi - 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. [API Development](/categories/api)
4. /
5. spiderhit/smsapi

ActiveLibrary[API Development](/categories/api)

spiderhit/smsapi
================

Laravel package to provide SMS API integration. Any SMS vendor that provides REST API can be used. SMS-API channel for Laravel notifications also included.

012PHPCI failing

Since Sep 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/spiderhit/smsapi)[ Packagist](https://packagist.org/packages/spiderhit/smsapi)[ RSS](/packages/spiderhit-smsapi/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Packagist](https://camo.githubusercontent.com/7879aecb41b0439e3efee7cecfc1657fd052f8b23aa950bb7ffe7d78660f2cdb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370696465726869742f736d736170692e737667)](https://packagist.org/packages/spiderhit/smsapi) [![Packagist](https://camo.githubusercontent.com/e989a7d9eec32b6f1b2e848128dadcb0e227f7b585e11917e0288176a5439c64/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370696465726869742f736d736170692e737667)](https://packagist.org/packages/spiderhit/smsapi) [![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://raw.githubusercontent.com/spiderhit/smsapi/master/LICENSE)

Integrate SMS API with Laravel
==============================

[](#integrate-sms-api-with-laravel)

Laravel package to provide SMS API integration. Any SMS vendor that provides REST API can be used.

#### [Star ⭐](https://github.com/spiderhit/smsapi) repo to show suport 😊

[](#star--repo-to-show-suport-)

Installation
------------

[](#installation)

### Install Package

[](#install-package)

Require this package with composer:

```
composer require spiderhit/smsapi

```

### Add Service Provider &amp; Facade

[](#add-service-provider--facade)

#### For Laravel 5.5+

[](#for-laravel-55)

Once the package is added, the service provider and facade will be autodiscovered.

#### For Older versions of Laravel

[](#for-older-versions-of-laravel)

Add the ServiceProvider to the providers array in `config/app.php`:

```
spiderhit\SmsApi\SmsApiServiceProvider::class,

```

Add the Facade to the aliases array in `config/app.php`:

```
'SmsApi': spiderhit\SmsApi\SmsApiFacade::class,

```

### Publish Config

[](#publish-config)

Once done, publish the config to your config folder using:

```
php artisan vendor:publish --provider="spiderhit\SmsApi\SmsApiServiceProvider"

```

Configuration
-------------

[](#configuration)

Once the config file is published, open `config/sms-api.php`

#### Global config

[](#global-config)

`country_code` : The default country code to be used

`default` : Default gateway

#### Gateway Config

[](#gateway-config)

Use can define multiple gateway configs like this:-

```
//    Gateway Configuration
    'gateway_name' => [
        'method' => 'GET', //Choose Request Method (GET/POST) Default:GET
        'url' => 'BaseUrl', //Base URL
        'params' => [
            'send_to_param_name' => '', //Send to Parameter Name
            'msg_param_name' => '', //Message Parameter Name
            'others' => [
                'param1' => '',
                'param2' => '',
                'param3' => '',
                //More params can be added
            ],
        ],
        'headers' => [
            'header1' => '',
            'header2' => '',
            //More headers can be added
        ],
//        'json' => true, // OPTIONAL: Use if you want the params to be sent in JSON format instead of query params (accepts true/false)
//        'wrapper' => 'wrapper_name', // OPTIONAL: Use only if you want the JSON request to be wrapped (accepts string)
        'add_code' => true, //Include Country Code (true/false)
    ],

```

#### Special Parameters in Gateway Config

[](#special-parameters-in-gateway-config)

##### `json` Parameter

[](#json-parameter)

The `json` parameter accepts `true/false`. When `true`, it sends `params` as a JSON payload. It also takes care of `'Content-Type' => 'application/json'` header.

##### `jsonToArray` Parameter

[](#jsontoarray-parameter)

The `jsonToArray` parameter accepts `true/false`. When `true`, it sends a single mobile number in an encapsulated array in the JSON payload. When `false`, a single mobile number is sent as text. Valid only when `json` parameter is `true`.

##### `wrapper` Parameter

[](#wrapper-parameter)

The `wrapper` is a special parameter which will be required only with some gateways. It wraps the JSON payload in the following structure:

```
"wrapper_name": [
    {
      "message": "Message",
      "to": [
        "Receipient1",
        "Receipient2"
      ]
    }
  ]

```

##### `wrapperParams` Parameter

[](#wrapperparams-parameter)

Accepts array. Used to add custom Wrapper Parameters. Parameters can also be added while calling the `smsapi()` function like `smsapi()->addWrapperParams(['wrapperParam1'=>'paramVal'])->sendMessage("TO", "Message")`

Usage
-----

[](#usage)

### Direct Use

[](#direct-use)

Use the `smsapi()` helper function or `SmsApi` facade to send the messages.

`TO`: Single mobile number or Multiple comma-separated mobile numbers

`MESSAGE`: Message to be sent

#### Using Helper function

[](#using-helper-function)

- Basic Usage `smsapi("TO", "Message");` or `smsapi()->sendMessage("TO","MESSAGE");`
- Adding extra parameters `smsapi("TO", "Message", ["param1" => "val"]);` or `smsapi()->sendMessage("TO", "Message", ["param1" => "val"]);`
- Adding extra headers `smsapi("TO", "Message", ["param1" => "val"], ["header1" => "val"]);` or `smsapi()->sendMessage("TO", "Message", ["param1" => "val"], ["header1" => "val"]);`
- Using a different gateway `smsapi()->gateway('GATEWAY_NAME')->sendMessage("TO", "Message");`
- Using a different country code `smsapi()->countryCode('COUNTRY_CODE')->sendMessage("TO", "Message");`
- Sending message to multiple mobiles `smsapi(["Mobile1","Mobile2","Mobile3"], "Message");` or `smsapi()->sendMessage(["Mobile1","Mobile2","Mobile3"],"MESSAGE");`

#### Using SmsApi facade

[](#using-smsapi-facade)

- Basic Usage `SmsApi::sendMessage("TO","MESSAGE");`
- Adding extra parameters `SmsApi::sendMessage("TO", "Message", ["param1" => "val"]);`
- Adding extra headers `SmsApi::sendMessage("TO", "Message", ["param1" => "val"], ["header1" => "val"]);`
- Using a different gateway `SmsApi::gateway('GATEWAY_NAME')->sendMessage("TO", "Message");`
- Using a different country code `SmsApi::countryCode('COUNTRY_CODE')->sendMessage("TO", "Message");`
- Sending message to multiple mobiles `SmsApi::sendMessage(["Mobile1","Mobile2","Mobile3"],"MESSAGE");`

### Use in Notifications

[](#use-in-notifications)

#### Setting up the Route for Notofication

[](#setting-up-the-route-for-notofication)

Add the method `routeNotificationForSmsApi()` to your Notifiable model :

```
public function routeNotificationForSmsApi() {
        return $this->phone; //Name of the field to be used as mobile
    }

```

By default, your User model uses Notifiable.

#### Setting up Notification

[](#setting-up-notification)

Add

`use spiderhit\SmsApi\Notifications\SmsApiChannel;`

and

`use spiderhit\SmsApi\Notifications\SmsApiMessage;`

to your notification.

You can create a new notification with `php artisan make:notification NOTIFICATION_NAME`

In the `via` function inside your notification, add `return [SmsApiChannel::class];` and add a new function `toSmsApi($notifiable)` to return the message body and parameters.

Notification example:-

```
namespace App\Notifications;

use spiderhit\SmsApi\Notifications\SmsApiChannel;
use spiderhit\SmsApi\Notifications\SmsApiMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    public function via($notifiable)
    {
        return [SmsApiChannel::class];
    }

    public function toSmsApi($notifiable)
    {
        return (new SmsApiMessage)
            ->content("Hello");
    }
}

```

You can also use `->params(["param1" => "val"])` to add extra parameters to the request and `->headers(["header1" => "val"])` to add extra headers to the request.

### Getting Response

[](#getting-response)

You can get response by using `->response()` or get the Response Code using `->getResponseCode()`. For example, `smsapi()->sendMessage("TO","MESSAGE")->response();`

Support
-------

[](#support)

Feel free to post your issues in the issues section.

Credits
-------

[](#credits)

Developed by [Spiderhit](https://github.com/spiderhit "Spiderhit")

License
-------

[](#license)

MIT

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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://avatars.githubusercontent.com/u/40608304?v=4)[spiderhit](/maintainers/spiderhit)[@spiderhit](https://github.com/spiderhit)

### Embed Badge

![Health badge](/badges/spiderhit-smsapi/health.svg)

```
[![Health](https://phpackages.com/badges/spiderhit-smsapi/health.svg)](https://phpackages.com/packages/spiderhit-smsapi)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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