parsgreen / sms
ParsGreen SMS gateway client for Laravel (send SMS, OTP, credit management, and more).
Requires
- php: ^8.1
- ext-curl: *
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.13
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpstan/phpstan: ^1.11|^2.0
- phpunit/phpunit: ^10.5|^11.0
This package is auto-updated.
Last update: 2026-08-09 12:04:10 UTC
README
A clean, reusable Laravel package for the ParsGreen SMS gateway — send SMS & OTP codes, calculate message parts, and manage your account credit across multiple websites.
Requirements
- PHP ^8.1
- Laravel ^10.0 | ^11.0 | ^12.0
- ext-curl
Installation
The package is published on Packagist:
composer require parsgreen/sms
For local development from a sibling folder, use a path repository instead:
"repositories": [ { "type": "path", "url": "../parsgreen-sms" } ]
composer require parsgreen/sms:@dev
Laravel auto-discovers the service provider and facade. If you have package discovery disabled, register them manually in bootstrap/providers.php (Laravel 11+) or config/app.php:
'providers' => [ ParsGreen\Sms\ParsGreenServiceProvider::class, ], 'aliases' => [ 'ParsGreen' => ParsGreen\Sms\Facades\ParsGreen::class, ],
Publish the config (optional)
php artisan vendor:publish --provider="ParsGreen\Sms\ParsGreenServiceProvider"
Configuration
Add these variables to your .env:
PARSGREEN_API_KEY=your-api-key PARSGREEN_BASE_URL=http://sms.parsgreen.ir PARSGREEN_VERIFY_SSL=false PARSGREEN_TIMEOUT=30
Or set them directly in config/parsgreen.php after publishing.
Usage
Every method returns a ParsGreen\Sms\ParsGreenResponse object:
| Property | Description |
|---|---|
success |
bool — whether the operation succeeded |
code |
`int |
message |
`string |
* |
Method-specific fields (e.g. Amount) |
Send an SMS
use ParsGreen\Sms\Facades\ParsGreen; $response = ParsGreen::sendSms('Hello!', ['09121111111', '09122222222']); // Optional dedicated sender number: $response = ParsGreen::sendSms('Hello!', ['09121111111'], '10001391'); if ($response->success) { foreach ($response->DataList as $item) { // $item->SendStatus, $item->Mobile, $item->ReqID } }
Send an OTP / activation code
Faster than a normal SMS. TemplateId ranges 0-6 (activation, verify, login codes).
$response = ParsGreen::sendOtp('09121111111', '1234', templateId: 0, addName: false);
Calculate SMS parts
$response = ParsGreen::smsCalc('سلام', '10001391'); echo $response->SmsPart; // number of SMS parts echo $response->IsUnicode; // whether the message is unicode
Account credit
$response = ParsGreen::credit(); echo $response->Amount;
Transfer credit between users
$response = ParsGreen::creditTransfer('fromUserName', 'toUserName', 1000);
Register a user
$response = ParsGreen::regUser([ 'firstName' => 'سحر', 'lastName' => 'افشار', 'company' => 'My Company', 'nationalCode' => '30030', 'email' => 'user@example.com', 'mobile' => '090500000', 'phone' => '021767676', 'description' => 'auto Register', ]); echo $response->UserID; // newly created user id
List sender numbers
// 1 => dedicated, 2 => public, 0 => all $response = ParsGreen::smsNumbers(0); foreach ($response->SmsNumbers as $number) { // ... }
Injection
You can also inject the client (e.g. into a controller or service):
use ParsGreen\Sms\ParsGreen; public function send(ParsGreen $parsGreen) { $parsGreen->sendSms('Hello!', ['09121111111']); }
Standalone usage (without Laravel)
use ParsGreen\Sms\ParsGreen; $client = ParsGreen::make('YOUR_API_KEY', 'http://sms.parsgreen.ir'); $client->sendSms('Hello!', ['09121111111']);
Error handling
ParsGreen\Sms\Exceptions\ConnectionException— network / cURL failuresParsGreen\Sms\Exceptions\InvalidResponseException— malformed or unexpected API responses- Both extend
ParsGreen\Sms\Exceptions\ParsGreenException, so you may catch the base exception (or the more specific ones) as needed.
API-level failures are reported through the response's success, code and message fields.
Development
composer install composer test # run the test suite (PHPUnit) composer analyse # static analysis (PHPStan + Larastan) composer format # fix code style (Pint) composer format:test # verify code style
The repository ships with GitHub Actions CI that runs the test suite, Pint and PHPStan across PHP 8.1–8.4 and Laravel 10–12.
License
MIT