PHP code example of isend / laravel

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

    

isend / laravel example snippets


use ISend\SMS\Facades\ISend;

// Fluent interface
ISend::to('218929000834')
    ->message('Your verification code is 1234')
    ->send();

// Get the SMS ID for tracking
$smsId = ISend::to('218929000834')
    ->message('Your verification code is 1234')
    ->send()
    ->getId();

// Static helper method
ISend::sendSms('218929000834', 'Your verification code is 1234');

// Send the same message to multiple recipients
ISend::to(['218929000834', '218929000836', '218929000837'])
    ->message('Important announcement for all users')
    ->send();

// Or as a comma-separated string
ISend::to('218929000834,218929000836,218929000837')
    ->message('Important announcement for all users')
    ->send();

ISend::to('218929000834')
    ->from('MyApp')  // Override the default sender ID
    ->message('Your verification code is 1234')
    ->send();

// Schedule a message for future delivery
ISend::to('218929000834')
    ->message('Reminder: Your appointment is tomorrow')
    ->scheduleAt('2025-12-31 09:00:00')  // Format: Y-m-d H:i
    ->send();

// For regions requiring DLT template registration
ISend::to('218929000834')
    ->message('Your OTP is 1234')
    ->dltTemplateId('template-123')
    ->send();

// Get the status of a sent message using its ID
$status = ISend::getStatus('sms-uid-123456');

// Example response structure
[
    'status' => 'success',
    'data' => [
        'uid' => 'sms-uid-123456',
        'status' => 'delivered',
        'sent_at' => '2025-01-01 12:00:00',
        'delivered_at' => '2025-01-01 12:00:05',
        // Additional status details...
    ]
]

// Get a list of all sent messages
$messages = ISend::listMessages();

// Send a campaign to a contact list
$campaign = ISend::sendCampaign(
    'contact-list-123',
    'Special offer for our valued customers!',
    'Marketing',  // Optional custom sender ID
    '2025-02-15 08:00:00'  // Optional schedule time
);

// Send to multiple contact lists
$campaign = ISend::sendCampaign(
    ['list-123', 'list-456'],
    'Special offer for all our customers!'
);

// Get profile information
$profile = ISend::getProfile();

// Check account balance
$balance = ISend::checkBalance();

// Get registered sender IDs
$senderIds = ISend::getSenderIds();

// Get transaction history
$transactions = ISend::getTransactions();

use ISend\SMS\Exceptions\ISendException;

try {
    ISend::to('invalid-number')
        ->message('Test message')
        ->send();
} catch (ISendException $e) {
    // Basic error information
    $message = $e->getMessage();
    $statusCode = $e->getStatusCode();
    
    // Detailed error data
    $responseData = $e->getResponseData();  // Full API response
    $requestData = $e->getRequestData();    // The request that caused the error
    
    // Error type helpers
    if ($e->isAuthenticationError()) {
        // Handle 401 errors (invalid API token)
    }
    
    if ($e->isValidationError()) {
        // Handle 422 errors (invalid parameters)
    }
    
    if ($e->isServerError()) {
        // Handle 5xx errors (server issues)
    }
    
    // Get complete error details as array
    $errorDetails = $e->toArray();
    
    // Log the error or handle as needed...
}

$response = ISend::to('218929000834')
    ->message('Test message')
    ->send()
    ->getLastResponse();
bash
php artisan isend:setup
bash
php artisan vendor:publish --tag="isend-config"