Why Send SMS Programmatically?

Automating SMS sending through code (programmatically) allows your application to trigger SMS notifications automatically — order confirmations, appointment reminders, verification codes, marketing campaigns, and more — without manual intervention.

Prerequisites

Basic PHP Function

<?php
function sendBulkSMS($api_key, $username, $password, $recipients, $message, $dlrurl = '') {
    $url = 'https://bulksms.schooldream.co.rw/api/v2/sms/send';
    $data = [
        'api_key'    => $api_key,
        'username'   => $username,
        'password'   => $password,
        'recipients' => is_array($recipients) ? implode(',', $recipients) : $recipients,
        'message'    => $message,
    ];
    if ($dlrurl) $data['dlrurl'] = $dlrurl;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $error = curl_error($ch);
    curl_close($ch);

    if ($error) {
        return ['status' => 'error', 'message' => $error];
    }

    return json_decode($response, true);
}

// Example usage:
$result = sendBulkSMS(
    'your_api_key',
    'your_username',
    'your_password',
    ['250782589800', '250782589801'],
    'Your order #1234 has been shipped!',
    'https://yourdomain.com/dlr-handler'
);

if ($result['status'] === 'success') {
    echo "Sent " . $result['totalmessages'] . " messages!";
} else {
    echo "Error: " . $result['message'];
}
?>

Error Handling

Always check the response status and handle errors appropriately. Common error codes include invalid credentials (401), daily limit reached (429), and invalid phone numbers (400).

Best Practices

Full API Documentation → · Interactive Playground →


Contact Us Try the API