Search by

A PHP wrapper for Kavenegar's API

Package info

github.com/KaveNegar/kavenegar-php

Homepage

Issues

pkg:composer/kavenegar/php

Statistics

Installs: 683 113

Dependents: 29

Suggesters: 1

Stars: 68

v2.1.0 2026-10-13 16:10 UTC

This package is auto-updated.

Last update: 2026-10-13 16:20:22 UTC


README


📱 Kavenegar PHP SDK

A modern, lightweight PHP client for SMS, OTP & Voice — fully typed and compliant down to PHP 5.4.


Packagist Version Downloads PHP Version


📦 Install · 🚀 Quick Start · 📝 DTO Requests · 📖 Docs · 🇮🇷 فارسی


✨ Features

  • 📦 Strict DTO Mapping: Method calls explicitly return fully structured model objects (e.g., SendResult, StatusResult) instead of raw, untyped associative arrays.
  • 🔧 Flexible Signatures: Supports both traditional parameter lists and C#-style request DTO objects.
  • ⚡ Zero External Dependencies: Built on native PHP CURL for high performance and compatibility.
  • 🌐 Broad Compatibility: Backwards-compatible down to PHP 5.4.0 (supports modern PHP 8.x, 7.x, 5.x).

📦 Installation

Install the package via Composer:

composer require kavenegar/php

🚀 Quick Start

Initialize the client with your API key:

require __DIR__ . '/vendor/autoload.php';

use Kavenegar\KavenegarApi;
use Kavenegar\Exceptions\ApiException;
use Kavenegar\Exceptions\HttpException;

$api = new KavenegarApi("YOUR_API_KEY");

try {
    // Send a simple SMS
    $result = $api->send("10004346", "09123456789", "Hello from Kavenegar PHP SDK!");
    
    foreach ($result as $sms) {
        echo "✅ Sent! Message ID: " . $sms->messageid . "\n";
    }
} catch (ApiException $e) {
    echo "❌ API Error: " . $e->errorMessage() . "\n";
} catch (HttpException $e) {
    echo "❌ Network Error: " . $e->errorMessage() . "\n";
}

📝 DTO Request Objects

For more structured request configuration, you can pass request DTOs directly to the methods:

Sending SMS with SendRequest

use Kavenegar\Models\SendRequest;

$req = new SendRequest();
$req->sender = "10004346";
$req->receptor = "09123456789";
$req->message = "OTP Code: 123456";
$req->policy = "policy_value"; // Optional policy

$result = $api->send($req);

Adding Templates with TemplateDto & Enums

use Kavenegar\Models\TemplateDto;
use Kavenegar\Enums\VerificationType;
use Kavenegar\Enums\VerificationUsageType;

$dto = new TemplateDto();
$dto->name = "otp-template-name";
$dto->textmessage = "Your verification code: %token%";
$dto->sourcetype = VerificationUsageType::MobileApplication;
$dto->sendmethod = VerificationType::Message;

$newTemplate = $api->addTemplate($dto);

🤝 Contributing

Contributions, bug reports, and pull requests are welcome!

🐛 Bug? Open an issue
💡 Idea? Submit a pull request
📧 Help? support@kavenegar.com

🇮🇷 راهنما

معرفی سرویس کاوه نگار

کاوه نگار یک وب سرویس ارسال و دریافت پیامک و تماس صوتی است که به راحتی میتوانید از آن استفاده نمایید.

ساخت حساب کاربری

اگر در وب سرویس کاوه نگار عضو نیستید میتوانید از لینک عضویت ثبت نام و اکانت آزمایشی برای تست API دریافت نمایید.

مستندات

برای مشاهده اطلاعات کامل مستندات وب سرویس پیامک به صفحه مستندات وب سرویس مراجعه نمایید.