PHPackages                             reedware/laravel-sms - 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. reedware/laravel-sms

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

reedware/laravel-sms
====================

Adds the ability to send text messages through various drivers.

v2.0.0(3y ago)235332MITPHPPHP &gt;=7.3

Since Sep 25Pushed 3y ago2 watchersCompare

[ Source](https://github.com/tylernathanreed/laravel-sms)[ Packagist](https://packagist.org/packages/reedware/laravel-sms)[ RSS](/packages/reedware-laravel-sms/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (6)Versions (11)Used By (2)

Laravel SMS
===========

[](#laravel-sms)

[![Latest Stable Version](https://camo.githubusercontent.com/3d7b25298070a276cfd50de6ac61e7d299baa06ab7adad2332caa578a57aad07/68747470733a2f2f706f7365722e707567782e6f72672f72656564776172652f6c61726176656c2d736d732f762f737461626c65)](https://packagist.org/packages/reedware/laravel-sms)[![Laravel Version](https://camo.githubusercontent.com/1e7a3bd7ea1f90cf9c820cd6106ad143ac4f93461b2ccfc8a555143ccfb949a2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382e782d2d31302e782d626c7565)](https://laravel.com/)[![Build Status](https://github.com/tylernathanreed/laravel-sms/workflows/tests/badge.svg)](https://github.com/tylernathanreed/laravel-sms/actions)

- [Introduction](#introduction)
    - [Configuration](#configuration)
    - [Driver Prerequisites](#driver-prerequisites)
- [Generating Textables](#generating-textables)
- [Writing Textables](#writing-textables)
    - [Configuring the Sender](#configuring-the-sender)
    - [Configuring the View](#configuring-the-view)
    - [View Data](#view-data)
- [Sending Text Messages](#sending-text-messages)
    - [Closure Messages](#closure-messages)
    - [Queueing Messages](#queueing-messages)
- [Rendering Textables](#rendering-textables)
    - [Previewing Textables in the Browser](#previewing-textables-in-the-browser)
- [Localizing Textables](#localizing-textables)
- [SMS &amp; Local Development](#sms-and-local-development)
- [Events](#events)
- [Adding Custom Providers](#adding-custom-providers)
    - [Deferred Registration](#deferred-registration)

Introduction
------------

[](#introduction)

This package provides a clean, simple service that integrates with SMS drivers, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Several driver implementations have been offloaded into separate packages so that you only have to include the integration for the drivers you need. Only drivers that don't require third party packages are included by default.

Supported Drivers
-----------------

[](#supported-drivers)

- Array
- Email
- Log
- Twilio (requires [reedware/laravel-sms-twilio](https://github.com/tylernathanreed/laravel-sms-twilio))

This package was also built such that anyone can add or override existing drivers, so that you aren't limited by what is provided out of the box.

### Configuration

[](#configuration)

The sms services may be configured via the `sms` configuration file. Each sms provider configured within this file may have its own options and even its own unique "transport", allowing your application to use different sms services to send certain sms messages. For example, your application might use Twilo to send transactional text messages while using Nexmo/Vonage to send bulk text messages.

### Driver Prerequisites

[](#driver-prerequisites)

The API based drivers such as Nexmo and Zenvia require the Guzzle HTTP library, which may be installed via the Composer package manager:

```
composer require guzzlehttp/guzzle

```

Additional drivers that require third party packages are not provided by default. You will need to install the driver specific package (which will include the third party dependencies for you). You can refer to the list of [Supported Drivers](#supported-drivers) to see which package you need to install.

#### Email Driver

[](#email-driver)

To use the Email driver, first ensure that your mailer is set up correctly. You may use any mail driver integrated with Laravel.

#### Twilio Driver

[](#twilio-driver)

To use the Twilio driver, first install the driver specific package:

```
composer require reedware/laravel-sms-twilio

```

Then set the `default` option in your `config/sms.php` configuration file to `twilio`. Next, verify that your twilio provider configuration file contains the following options:

```
'your-driver-name' => [
    'transport' => 'twilio',
    'account_sid' => 'your-twilio-account-sid',
    'auth_token' => 'your-twilio-auth-token'
],

```

If you are not using the "US" [Twilio region](https://www.twilio.com/docs/global-infrastructure/edge-locations/legacy-regions), you may define your region id in the provider configuration:

```
'your-driver-name' => [
    'transport' => 'twilio',
    'account_sid' => 'your-twilio-account-sid',
    'auth_token' => 'your-twilio-auth-token',
    'region' => 'sg1' // singapore
],

```

Additionally, ssl host and peer verification is disabled by default. To enable this, you may include the verify flag in the provider configuration:

```
'your-driver-name' => [
    'transport' => 'twilio',
    'account_sid' => 'your-twilio-account-sid',
    'auth_token' => 'your-twilio-auth-token',
    'verify' => true
],

```

Additional instructions can be found in the [Laravel SMS Twilio](https://github.com/tylernathanreed/laravel-sms-twilio) package documentation.

Generating Textables
--------------------

[](#generating-textables)

Each type of text message sent by your application is represented as a "textable" class. These classes will be stored in the `app/SMS` directory by default. You can generate a new textable using the `make:sms` command:

```
php artisan make:sms OrderShipped

```

Writing Textables
-----------------

[](#writing-textables)

All of a textable class' configuration is done in the `build` method. Within this method, you may call various methods such as `from`, `to`, and `view` to configure the message's presentation and delivery.

### Configuring the Sender

[](#configuring-the-sender)

#### Using the `from` Method

[](#using-the-from-method)

First, let's explore configuring the sender of the text message. Or, in other words, who the message is going to be "from". There are two ways to configure the sender. First, you may use the `from` method within your textable class' `build` method:

```
/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('9995551234')
                ->view('sms.orders.shipped');
}

```

#### Using a Global `from` Address

[](#using-a-global-from-address)

However, if your application uses the same "from" number for all of its text messages, it can become cumbersome to call the `from` method in each textable class you generate. Instead, you may specify a global "from" number in your `config/sms.php` configuration file. This address will be used if no other "from" address is specified within the textable class:

```
'from' => '9995551234',

```

Alternatively, you may also define a "from" number for the sms provider specifically:

```
'your-driver-name' => [
    'transport' => 'email',
    'from' => '9995551234'
],

```

### Configuring the View

[](#configuring-the-view)

Within a textable class' `build` method, you may use the `view` method to specify which template should be used when rendering the text message's contents:

```
/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('sms.orders.shipped');
}

```

> You may wish to create a `resources/views/sms` directory to house all of your sms templates; however, you are free to place them wherever you wish within your `resources/views` directory.

#### Plain Text Messages

[](#plain-text-messages)

If you would like to define your message as pre-rendered text, you may use the `text` method. Unlink the `view` method, the `text` method the already rendered contents the message.

```
/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->text('Your order has been shipped!');
}

```

### View Data

[](#view-data)

#### Via Public Properties

[](#via-public-properties)

Typically, you will want to pass some data to your view that you can utilize when rendering the text message. There are two ways you may make data available to your view. First, any public property defined on your textable class will automatically be made available to the view. So, for example, you may pass data into your textable class' constructor and set that data to public properties defined on the class:

```
