PHP code example of codexoft / mobilesasa-sdk

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

    

codexoft / mobilesasa-sdk example snippets


use Codexoft\MobilesasaSDK\Mobilesasa;

$config = [
    'senderId' => 'YOUR_SENDER_ID',
    'apiKey' => 'YOUR_API_KEY',
    'mobileServeyKey' => 'YOUR_SURVEY_KEY',
    'showBalance' => true, // Optional: Show balance in responses
    'shortCode' => 'YOUR_SHORT_CODE' // Optional: For short code messaging
];

$mobilesasa = new Mobilesasa($config);

$response = $mobilesasa->sendSMS('0712345678', 'Hello World!');

$phoneNumbers = ['0712345678', '0723456789'];
$response = $mobilesasa->sendBulkSms($phoneNumbers, 'Hello everyone!');

$details = $mobilesasa->phoneNumberDetails('0712345678');

$messageInfo = $mobilesasa->calculateMessageLength('Your message here');

$status = $mobilesasa->smsDeliveryStatus('message_id');

$messageBody = [
    [
        'phone' => '0712345678',
        'message' => 'Hello John!'
    ],
    [
        'phone' => '0723456789',
        'message' => 'Hello Jane!'
    ]
];
$response = $mobilesasa->sendPersonalizedBulkSms($messageBody);

$groups = $mobilesasa->smsGroups();

$contactDetails = [
    'name' => 'John Doe',
    'phone' => '0712345678',
    'email' => '[email protected]' // Optional
];
$response = $mobilesasa->addToGroup('GROUP_CODE', $contactDetails);

$response = $mobilesasa->deleteFromGroup('GROUP_CODE', '0712345678');

$groups = $mobilesasa->anniversaryGroups();

$contactDetails = [
    'name' => 'John Doe',
    'phone' => '0712345678',
    'date' => '2024-01-01'
];
$response = $mobilesasa->addToAnniversaryGroup('GROUP_CODE', $contactDetails);

$response = $mobilesasa->deleteFromAnniversaryGroup('GROUP_CODE', '0712345678');

$contactDetails = [
    'name' => 'John Doe',
    'phone' => '0712345678'
];

// Send immediately
$response = $mobilesasa->mobileServey('SURVEY_ID', $contactDetails);

// Schedule for later
$response = $mobilesasa->mobileServey(
    'SURVEY_ID',
    $contactDetails,
    false,
    '2024-01-20 10:00:00',
    '2024-01-20 18:00:00'
);

try {
    $response = $mobilesasa->sendSMS('0712345678', 'Hello World!');
} catch (MobilesasaException $e) {
    echo 'Error: ' . $e->getMessage();
    echo 'Status Code: ' . $e->getStatusCode();
    echo 'Response: ' . print_r($e->getResponse(), true);
}