PHPackages                             laravelsms/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. laravelsms/sms

ActivePackage[Utility &amp; Helpers](/categories/utility)

laravelsms/sms
==============

Laravel 5 PhpSms Package

366546[1 issues](https://github.com/phper2013/laravel-sms/issues)PHP

Since Jan 18Pushed 8y ago2 watchersCompare

[ Source](https://github.com/phper2013/laravel-sms)[ Packagist](https://packagist.org/packages/laravelsms/sms)[ RSS](/packages/laravelsms-sms/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

laravel sms
===========

[](#laravel-sms)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3a51c2fbb6801e704dea3d42e778c8c2804cbeb357a6f5efc5847cd4308e1359/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c736d732f736d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelsms/sms)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/9d6f2dce385c818709955de8aae9baadf0bce0bf9aed54125beab23101da33f0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706572323031332f6c61726176656c2d736d732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phper2013/laravel-sms/build-status/master)[![Coverage Status](https://camo.githubusercontent.com/8129ecbfc3190ad98e1c8a45001f3f763ead2febfb0c2f5546b6565c723a264e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706572323031332f6c61726176656c2d736d732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/laravelsms/sms/code-structure)[![Quality Score](https://camo.githubusercontent.com/633939c03a1c04dbfb71adebd5d02806eb9bc85d404117df3ce4d34fbba79f7a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706572323031332f6c61726176656c2d736d732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phper2013/laravel-sms/badges/coverage.png?b=master)[![Total Downloads](https://camo.githubusercontent.com/b0b09942e2872c790569bd44f9be6f00d33850ac5488fc1ea6496c27c87678bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c736d732f736d732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laravelsms/sms)

基于 laravel 5.3+ 开发的轻量化手机短信服务包，特点：简单，灵活

> 支持：阿里云短信、云片网络、容联·云通讯、赛邮·云通讯、Luosimao、腾讯云短信

> 适合场景：手机验证、订单消息、通知提醒等

安装
--

[](#安装)

Via Composer

```
composer require laravelsms/sms:dev-master

or

composer require laravelsms/sms
```

composer.json

```
"laravelsms/sms": "dev-master"
```

配置
--

[](#配置)

```
//服务提供者
'providers' => [
        // ...
        Laravelsms\Sms\SmsServiceProvider::class,
    ]

//别名
'aliases' => [
    //...
    'Sms' => Laravelsms\Sms\Facades\Sms::class,
]

//创建配置文件
php artisan vendor:publish --tag=phpsms
```

配置项(.env)
---------

[](#配置项env)

> 以下为本程序所支持的短信代理平台的配置参考：

```
//默认短信平台
SMS_DEFAULT=aLiYun

//备用短信平台（非自动化，仅作为变量提供，需自行程序处理，适合当主平台出现状况后使用。）
SMS_FALLBACK=subMail

//默认签名（重要：签名要用{}括起来）
SMS_SIGNNAME={辣妈羊毛党}

YUNPIAN_APIKEY=your-appkey
YUNPIAN_TEMPLATECONTENT=模板内容   //参考：您的验证码是{verifyCode}，有效期为{time}分钟，请尽快验证

LUOSIMAO_APIKEY=your-appkey
LUOSIMAO_TEMPLATECONTENT=模板内容  //参考：{verifyCode}是您请求的验证码

SUBMAIL_APPID=your-appid
SUBMAIL_APIKEY=your-appkey
SUBMAIL_TEMPLATEID=模板ID          //（project Id）参考：3OZtl

YUNTONGXUN_ACCOUNTSID=your-account-sid
YUNTONGXUN_ACCOUNTTOKEN=your-account-token
YUNTONGXUN_APPID=your-appid
YUNTONGXUN_TEMPLATEID=模板ID      //参考：1~N

ALIYUN_APPKEY=your-appkey
ALIYUN_APPSECRET=your-appsecret
ALIYUN_TEMPLATEID=模板ID         //参考：SMS_57930028

QQYUN_APPID=your-sdkappid
QQYUN_APPKEY=your-appkey
QQYUN_TEMPLATEID=模板ID         //参考：76068
```

使用示例
----

[](#使用示例)

### 1、使用不同的短信平台

[](#1使用不同的短信平台)

```
//调用默认短信平台
$smsDriver = Sms::driver();

//调用备用短信平台
$smsDriver = Sms::driver('fallback');

$smsDriver = Sms::driver('aLiYun');

$smsDriver = Sms::driver('yunPian');

$smsDriver = Sms::driver('yunTongXun');

$smsDriver = Sms::driver('subMail');

$smsDriver = Sms::driver('luoSiMao');

$smsDriver = Sms::driver('qqYun');
```

### 2、程序自带标签变量说明

[](#2程序自带标签变量说明)

```
{verifyCode} 模板数据验证码变量
{time} 模板数据有效时间变量
['yzm' => 'verifyCode'] 说明：'yzm'表示官方模板变量名，'verifyCode' 表示使用程序自带的生成验证码功能
```

### 3、用户定义模板说明(重要)

[](#3用户定义模板说明重要)

> 官方模板变量格式多样，如###、#变量名#、@var(变量名)等，本包统一命名格式为：{变量名}，变量名和位置应与官方模板变量名和位置保持一致

### 4、基本发送方式

[](#4基本发送方式)

```
$mobile = '13*********';  //手机号
```

> 使用模板方式发送,无需设置content(如:容联·云通讯、赛邮·云通讯、阿里云短信、腾讯云短信)

```
$templateVar = ['yzm' => 'verifyCode'];          //verifyCode表示使用程序自动生成的验证码
$smsDriver->setTemplateVar($templateVar, true);  //替换模板变量，true表示返回键值对数组，false表示返回值数组
$result = $smsDriver->singlesSend($mobile);    //发送短信,返回结果
```

> 腾讯云短信，默认国家码为86，其它国家和地区的编码必须填写, 国内短信格式：$mobile = '13\*\*\*\*\*\*' 或 $mobile = \['86', '13\*\*\*\*\*\*\*\*\*'\], 其它国家和地区短信格式：$mobile = \['82', '016\*\*\*\*\*\*\*\*'\]

```
$result = $smsDriver->singlesSend($mobile);

or

$mobile = ['82', '016********'];
$result = $smsDriver->singlesSend($mobile);
```

> 使用内容方式发送,无需设置模板id和模板var(如:云片网络、luosimao)

```
$smsDriver->setContentByVerifyCode();
//假设模板内容为：“{verifyCode}是您请求的验证码”，程序转化为：761888是您请求的验证码
$result = $smsDriver->singlesSend($mobile);

Or

$smsDriver->setContentByVerifyCode(20);
//假设模板内容为：“您的验证码是{verifyCode}，有效期为{time}分钟”，程序转化为：您的验证码是761888，有效期为20分钟
$result = $smsDriver->singlesSend($mobile);

Or

$content = '尊敬的用户，您的域名已到期，请及时续费';  //设置短信内容
$smsDriver->setContent($content);
$result = $smsDriver->singlesSend($mobile);
```

### 5、组合发送方式

[](#5组合发送方式)

> 设置签名

```
$smsDriver->setSignName('雷神');
```

> 设置内容

```
$smsDriver->setContent($content);
```

> 替换内容中验证码变量(程序生成验证码方式)

```
$smsDriver->setContentByVerifyCode();
```

> 替换内容中验证码变量(程序生成验证码方式)及有效时间

```
$smsDriver->setContentByVerifyCode(20);
```

> 替换内容中自定义变量（array $templateVar）

```
$smsDriver->setContentByCustomVar($templateVar);
```

> 设置内容并替换内容的变量（array $templateVar）

```
$content = '{name},您的帐号异地登录，如要不是你本人操作，请及时修改密码';  //设置短信内容
$templateVar = ['name' => 'discovery'];  //替换模板内容变量
$smsDriver->setContent($content);
$smsDriver->setContentByCustomVar($templateVar);
//程序转化为：discovery,您的帐号异地登录，如要不是你本人操作，请及时修改密码
```

> 设置模板ID

```
$smsDriver->setTemplateId(1);
```

> 替换模板变量，返回值数组（array $templateVar）

```
$smsDriver->setTemplateVar($templateVar);

//参考
 array(2) {
   [0]=>
   string(8) "931101"
   [1]=>
   string(4) "10"
 }
```

> 替换模板变量，true表示返回键值对数组（array $templateVar）

```
$smsDriver->setTemplateVar($templateVar, true);

//参考
.array(2) {
  ["verifyCode"]=>
  string(6) "859432"
  ["time"]=>
  string(2) "15"
}
```

> 发送

```
$smsDriver->singlesSend($mobile);
```

> 返回拼接后的发送数据

```
$smsDriver->singlesSend($mobile, false);
```

### 6、更多组合详细请参见单元测试文件：PhpSmsUnitTest.php

[](#6更多组合详细请参见单元测试文件phpsmsunittestphp)

### 7、判断短信发送成功还是失败

[](#7判断短信发送成功还是失败)

> return array $result 返回数组结果

> return int $result\[\].code 返回0则成功，返回其它则错误

> return string $result\[\].msg 返回消息： "发送成功" Or 短信代理平台提示消息

> return int $result\[\].verifyCode 返回程序自动生成的验证码，如果不使用程序自带的验证码生成功能，此变量值为NULL， 需自行传递验证码值

```
array(3) {
  ["verifyCode"]=>
  int(977178)
  ["code"]=>
  int(0)
  ["msg"]=>
  string(12) "发送成功"
}
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

拷贝单元测试文件PhpSmsUnitTest.php到根目录tests文件中

```
$ vendor/bin/phpunit tests/PhpSmsUnitTest.php
```

Security
--------

[](#security)

> If you discover any security related issues, please email  instead of using the issue tracker.

> 如果你发现任何相关的问题，请把问题以邮件的形式发送至。

License
-------

[](#license)

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

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.7% 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/0b0a7b94848858560c0fb048b56c39e6b26aa728c1461ec9d3d6c26627f99219?d=identicon)[phper2013](/maintainers/phper2013)

---

Top Contributors

[![phper2013](https://avatars.githubusercontent.com/u/3482615?v=4)](https://github.com/phper2013 "phper2013 (11 commits)")[![discovery1001](https://avatars.githubusercontent.com/u/6139597?v=4)](https://github.com/discovery1001 "discovery1001 (6 commits)")

---

Tags

laravel-smsphpsmssms

### Embed Badge

![Health badge](/badges/laravelsms-sms/health.svg)

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

PHPackages © 2026

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