PHP SMS API Integration Guide

Complete guide to integrate SMS API with PHP applications. Code examples, best practices, and troubleshooting tips.

PHP SMS API Integration Guide

Learn how to integrate SMS functionality into your PHP applications using our REST API. This guide covers everything from basic setup to advanced features.

Prerequisites

  • PHP 7.0 or higher
  • cURL extension enabled
  • Valid API key from OnlineSMSService
  • Basic knowledge of PHP and HTTP requests

Basic Integration

Simple SMS Sending

 "919876543210",
    "message" => "Your OTP is: 123456",
    "sender" => "OTPSMS",
    "type" => "transactional"
];

// Send SMS using cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($smsData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Authorization: Bearer " . $apiKey
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

if ($httpCode === 200) {
    $result = json_decode($response, true);
    echo "SMS sent successfully! Message ID: " . $result['message_id'];
} else {
    echo "Failed to send SMS. Error: " . $response;
}
?>

Advanced Features

Bulk SMS Sending

 $number,
        "message" => "Bulk message content",
        "sender" => "BULK",
        "type" => "promotional"
    ];
    
    // Send SMS (use the same cURL code as above)
    sendSMS($smsData);
}
?>

Error Handling

Ready to Start Integrating SMS?

Get your API key and start sending SMS messages in minutes

Get API Key Try API Playground