overtrue/easy-sms
A flexible SMS sending package for PHP/Laravel with a unified API for multiple providers. Supports templates, verification codes, failover and load balancing, and easy configuration so you can switch gateways without changing your application code.
overtrue/easy-sms) is designed as a multi-channel SMS gateway abstraction layer, fitting seamlessly into Laravel’s service-oriented architecture. It decouples SMS logic from business logic, adhering to the Single Responsibility Principle (SRP).SmsSent, SmsFailed) for async processing or notifications..env, config/easy-sms.php) and facade/service usage (e.g., EasySms::send()).fake() for SMS).EasySms::send() → queue:work).EasySms::fake()).composer require overtrue/easy-sms
php artisan vendor:publish --provider="Overtrue\EasySms\EasySmsServiceProvider"
.env and config/easy-sms.php with provider credentials.EasySms::send():
EasySms::send('aliyun', [
'to' => '15012345678',
'data' => 'Hello, world!',
]);
twilio, custom_http) based on provider.EasySms::send('aliyun', [...], ['queue' => 'sms']);
Event::listen(SmsSent::class, function ($event) {
Log::info("SMS sent to {$event->phone}");
});
cURL/Guzzle may be needed for custom HTTP channels.easy_sms_logs) can be migrated via:
php artisan migrate
(If using database logging.)| Priority | Task | Dependencies |
|---|---|---|
| 1 | Install & configure package | Composer, Laravel project |
| 2 | Replace direct SMS calls with EasySms facade |
Existing SMS logic |
| 3 | Set up queue workers (if high volume) | Laravel Queues |
| 4 | Implement fallback logic (e.g., retry failed sends) | Provider API stability |
| 5 | Add monitoring/logging | Laravel Observers/Events |
overtrue/easy-sms for provider API changes (e.g., Twilio v2023 → v2024).EasySms::debug() to log raw API responses for troubleshooting.custom_http for bulk sends).| Failure Scenario | Mitigation Strategy | Detection |
|---|---|---|
| Provider API Outage | Implement multi-channel fallback (e.g., aliyun → twilio). |
Laravel Events (SmsFailed) + Alerts (e.g., Laravel Echo). |
| Rate Limiting | Use exponential backoff in queue workers. | Monitor failed_jobs table. |
| Credential Leak | Rotate API keys via Vault (e.g., HashiCorp Vault). | Audit logs (e.g., Laravel’s auth.log). |
| SMS Content Rejection | Validate content before sending (e.g., Laravel Validation). | Provider API rejection responses. |
| Database Log Overload | Archive old logs via Laravel Scheduler or external storage (S3). | Monitor easy_sms_logs table size. |
EasySms facade usage and channel configuration.barryvdh/laravel-ide-helper) for autocompletion.How can I help you explore Laravel packages today?