PHP code example of jamal13647850 / sms-api

1. Go to this page and download the library: Download jamal13647850/sms-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jamal13647850 / sms-api example snippets



declare(strict_types=1);

SMS;
use jamal13647850\smsapi\SMS;

// Create a gateway instance (e.g., FarazSMS)
$gateway = new FarazSMS(
    'your_username', 
    'your_password', 
    'your_sender_number'
);

// Create the SMS service with your chosen gateway
$sms = new SMS($gateway);

// Send a simple SMS
$result = $sms->sendSMS('09120000000', 'Hello, this is a test message');

// Check the result
if ($result['status']) {
    echo "SMS sent successfully! Message ID: " . $result['resultData'];
} else {
    echo "Failed to send SMS. Error ({$result['resultCode']}): " . $result['resultData'];
}

// Check your account balance
$credit = $sms->getCredit();
echo "Your remaining credit: " . $credit;

[
    'status' => true|false,      // Boolean indicating success/failure
    'resultCode' => 0,           // Provider-specific result code
    'resultData' => mixed        // Message ID, error message, or data
]

$result = $sms->sendSMS('09120000000', 'Your message here');

$numbers = ['09120000000', '09987654321'];
$result = $sms->sendSMS($numbers, 'Your message here');

$parameters = [
    'name' => 'John',
    'code' => '1234'
];
$result = $sms->sendSMSByPattern('09120000000', '', 12345, $parameters);

use jamal13647850\smsapi\Melipayamak;
use jamal13647850\smsapi\SMS;

$gateway = new Melipayamak(
    '09109568855',
    'c4150f06-312c-4152-b76b-34ac9c525437',
    '50004000882270'
);

$sms = new SMS($gateway);

// Send pattern SMS with Persian parameter
$result = $sms->sendSMSByPattern(
    '09124118355',
    '',
    '185341',                    // Pattern ID
    ['product' => 'فرش دستباف'] // Parameter value
);

if ($result['status']) {
    echo "Pattern SMS sent! Message ID: " . $result['resultData'];
    // Output: Pattern SMS sent! Message ID: 5343713930900543701
}

$credit = $sms->getCredit();

$status = $sms->getSMSStatus('message-id-here');
// Returns: 'sent', 'delivered', 'failed', 'pending', or 'unknown'

$messages = $sms->receiveSMS();

use jamal13647850\smsapi\FarazSMS;

$gateway = new FarazSMS(
    'your_username',
    'your_password',
    'your_sender_number', 
    'https://ippanel.com/services.jspd' // optional URL
);

use jamal13647850\smsapi\SMSir;

$gateway = new SMSir(
    'your_api_key',
    'your_sender_number', 
    'https://api.sms.ir/v1/send/' // optional URL
);

use jamal13647850\smsapi\FaraPayamak;

$gateway = new FaraPayamak(
    'your_username',
    'your_password',
    'your_sender_number',
    'https://rest.payamak-panel.com/api/SendSMS/' // optional URL
);

use jamal13647850\smsapi\Elanak;

$gateway = new Elanak(
    'your_username',
    'your_password',
    'your_sender_number',
    'http://158.58.186.243/webservice/' // optional URL
);

use jamal13647850\smsapi\MedianaSMS;

$gateway = new MedianaSMS(
    'your_username',
    'your_password',
    'your_sender_number',
    'https://ippanel.com/services.jspd' // optional URL
);

use jamal13647850\smsapi\Melipayamak;

$gateway = new Melipayamak(
    'your_username',           // Username from panel
    'your_apikey',             // ApiKey from Developers menu (NOT password!)
    'your_sender_number',      // e.g., 50004000882270
    'https://rest.payamak-panel.com/api/SendSMS/' // optional URL
);

// Send SMS using pattern with parameter
$result = $gateway->sendSMSByPattern(
    '09124118355',                    // Recipient
    '',                               // Empty message (not used with patterns)
    '185341',                         // Pattern ID from panel
    ['product' => 'فرش دستباف']      // Pattern parameters
);

if ($result['status']) {
    echo "Pattern SMS sent! Message ID: " . $result['resultData'];
}

// Using FarazSMS
$farazGateway = new FarazSMS('username', 'password', 'number');
$sms = new SMS($farazGateway);
$sms->sendSMS('09120000000', 'Test message');

// Switch to SMS.ir
$smsirGateway = new SMSir('api_key', 'number');
$sms = new SMS($smsirGateway);
$sms->sendSMS('09120000000', 'Test message');

$result = $sms->sendSMS('09120000000', 'Test message');

if ($result['status']) {
    // Success
    $messageId = $result['resultData'];
} else {
    // Error
    $errorCode = $result['resultCode'];
    $errorMessage = $result['resultData'];
    
    echo "Error {$errorCode}: {$errorMessage}";
}
bash
php test.php