PHP code example of erbitron / dialog-esms

1. Go to this page and download the library: Download erbitron/dialog-esms 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/ */

    

erbitron / dialog-esms example snippets


use Erbitron\DialogESMS\DialogESMSClient;

$client = new DialogESMSClient('your-api-key');

$response = $client->sendMessage(
    recipients: '94771234567',
    message: 'Hello from website',
    sourceAddress: 'YourBrand'
);

if ($response->successful()) {
    echo 'SMS sent';
} else {
    echo $response->message;
}

use Erbitron\DialogESMS\DialogESMSClient;

class SmsController
{
    public function send(DialogESMSClient $sms)
    {
        $response = $sms->sendMessage(
            recipients: '94771234567',
            message: 'Your OTP is 123456',
            sourceAddress: 'YourBrand'
        );

        return $response->message;
    }
}

use DialogESMS;

$response = DialogESMS::checkBalance();

use Erbitron\DialogESMS\DialogESMSClient;

$client = new DialogESMSClient('your-api-key');

$response = $client->sendMessage(
    recipients: '94771234567',
    message: 'Hello from website',
    sourceAddress: 'YourBrand'
);

if ($response->successful()) {
    echo 'SMS sent';
} else {
    echo $response->message;
}

use Erbitron\DialogESMS\DialogESMSClient;

$client = new DialogESMSClient('your-api-key');
$response = $client->checkBalance();

echo $response->message;
echo $response->balance ?? '';

use Erbitron\DialogESMS\DialogESMSClient;
use Erbitron\DialogESMS\Exceptions\DialogESMSException;

try {
    $client = new DialogESMSClient('your-api-key');
    $response = $client->sendMessage(
        recipients: '94771234567',
        message: 'Hello',
        sourceAddress: 'YourBrand'
    );
} catch (DialogESMSException $e) {
    report($e);
}
bash
php artisan vendor:publish --tag=dialog-esms-config