PHP code example of limon / laravel-zender

1. Go to this page and download the library: Download limon/laravel-zender 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/ */

    

limon / laravel-zender example snippets


use Zender\Laravel\Facades\Zender;

// Send Single SMS via Gateway Device
$response = Zender::sms()->send([
    'mode' => 'devices',
    'phone' => '+1234567890',
    'message' => 'Hello! {Your order #1001 is now shipped.|Thank you for your purchase!}',
    'device' => 'DEVICE_UNIQUE_ID',
    'sim' => 1,
    'priority' => 1, // 1 = Immediate, 2 = Queued
]);

// Send Bulk SMS
$response = Zender::sms()->sendBulk([
    'mode' => 'gateways',
    'campaign' => 'Summer Discount Campaign',
    'message' => 'Special offer for you!',
    'numbers' => '+1234567890,+9876543210',
    'gateway' => 5,
]);

// Send WhatsApp Text Message
$response = Zender::whatsapp()->send([
    'account' => 'WA_ACCOUNT_UNIQUE_ID',
    'recipient' => '+1234567890',
    'message' => 'Hello via WhatsApp!',
]);

// Send WhatsApp Image/Media via Direct URL
$response = Zender::whatsapp()->send([
    'account' => 'WA_ACCOUNT_UNIQUE_ID',
    'recipient' => '+1234567890',
    'type' => 'media',
    'message' => 'Check out our new catalog!',
    'media_url' => 'https://example.com/catalog.jpg',
    'media_type' => 'image', // image, audio, or video
]);

// Send WhatsApp PDF Document from local file
$response = Zender::whatsapp()->send([
    'account' => 'WA_ACCOUNT_UNIQUE_ID',
    'recipient' => '+1234567890',
    'type' => 'document',
    'message' => 'Attached invoice',
    'document_file' => storage_path('app/invoices/inv_1001.pdf'),
]);

// Validate if a number exists on WhatsApp
$validation = Zender::whatsapp()->validate('WA_ACCOUNT_UNIQUE_ID', '+1234567890');

// Send OTP via SMS
$otp = Zender::otp()->send([
    'type' => 'sms',
    'phone' => '+1234567890',
    'message' => 'Your security code is {otp}. Valid for 5 minutes.',
    'expire' => 5,
    'mode' => 'devices',
    'device' => 'DEVICE_UNIQUE_ID',
]);

// Verify User Inputted OTP
$verification = Zender::otp()->verify('543210');

if ($verification['status'] === 200) {
    // OTP is valid!
}

$credits = Zender::account()->getCredits();
$subscription = Zender::account()->getSubscription();



use Zender\Zender;

$zender = new Zender([
    'site_url' => 'https://sms.yourdomain.com/',
    'api_secret' => 'your_api_secret_here',
    'timeout' => 30,
    'verify_ssl' => true,
]);

// Send SMS
$result = $zender->sms()->send([
    'mode' => 'devices',
    'phone' => '+1234567890',
    'message' => 'Hello from pure PHP!',
    'device' => 'DEVICE_UNIQUE_ID',
]);

use Zender\Exceptions\ZenderApiException;
use Zender\Laravel\Facades\Zender;

try {
    $response = Zender::sms()->send([
        'mode' => 'devices',
        'phone' => '+1234567890',
        'message' => 'Hello!',
        'device' => 'INVALID_DEVICE_ID',
    ]);
} catch (ZenderApiException $e) {
    echo "API Error Code: " . $e->getStatusCode() . "\n";
    echo "Error Message: " . $e->getMessage() . "\n";
    print_r($e->getResponseBody());
}
bash
php artisan vendor:publish --tag=zender-config