SMS Gateway Integration Guides
Production-ready code examples for PHP, Node.js, Python, Salesforce, WordPress, and Laravel — send your first SMS in under 5 minutes.
PHP SMS Integration
Learn how to integrate SMS gateway with PHP using cURL and our REST API. The most popular integration method for Indian web applications.
Steps:
- Get your API key from the dashboard
- Install cURL extension if not already installed
- Create a new PHP file for SMS functionality
- Write the SMS sending function using cURL
- Test the integration with a sample message
Code Sample:
<?php
function sendSMS($to, $message, $apiKey) {
$url = "https://api.onlinesmsservice.com/v1/send";
$data = [
"to" => $to,
"message" => $message,
"type" => "transactional"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Authorization: Bearer " . $apiKey
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
// Usage
$result = sendSMS("919999999999", "Hello!", "your_api_key");
echo json_encode($result);
Node.js SMS Integration
Integrate SMS gateway with Node.js using axios and async/await. Perfect for modern JavaScript apps, Express servers, and serverless functions.
Steps:
- Create a new Node.js project
- Install axios package
- Create SMS service module
- Implement SMS sending function
- Add error handling and testing
Code Sample:
const axios = require("axios");
class SMSService {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseURL = "https://api.onlinesmsservice.com/v1";
}
async sendSMS(to, message, type = "transactional") {
const response = await axios.post(
`${this.baseURL}/send`,
{ to, message, type },
{
headers: {
"Authorization": `Bearer ${this.apiKey}`
}
}
);
return response.data;
}
}
// Usage
const sms = new SMSService("your_api_key");
sms.sendSMS("919999999999", "Hello from Node.js!")
.then(result => console.log(result));
Python SMS Integration
Send SMS using Python with the requests library and our REST API. Ideal for Django, Flask, FastAPI, and data pipeline projects.
Steps:
- Install requests library
- Create Python script for SMS
- Implement SMS sending function
- Add error handling
- Test the integration
Code Sample:
import requests
class SMSService:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://api.onlinesmsservice.com/v1"
def send_sms(self, to, message, msg_type="transactional"):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {self.api_key}"
}
data = {"to": to, "message": message, "type": msg_type}
response = requests.post(
f"{self.base_url}/send",
json=data, headers=headers
)
response.raise_for_status()
return response.json()
# Usage
sms = SMSService("your_api_key")
result = sms.send_sms("919999999999", "Hello from Python!")
print(result)
Salesforce SMS Integration
Integrate SMS gateway with Salesforce using Apex and REST API callouts. Automate customer communications directly from your CRM.
Steps:
- Create custom Apex class for SMS
- Implement HTTP callout method
- Add Remote Site Settings for our API
- Create Process Builder / Flow trigger
- Test with Salesforce org
Code Sample:
public class SMSService {
private static final String API_URL =
"https://api.onlinesmsservice.com/v1/send";
@future(callout=true)
public static void sendSMS(String phone, String msg) {
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(API_URL);
request.setMethod("POST");
request.setHeader("Content-Type", "application/json");
request.setHeader("Authorization", "Bearer YOUR_KEY");
request.setBody(JSON.serialize(new Map<String, Object>{
"to" => phone,
"message" => msg,
"type" => "transactional"
}));
HttpResponse response = http.send(request);
System.debug("Status: " + response.getStatusCode());
}
}
WordPress Plugin
Add SMS functionality to WordPress using a custom plugin. Send notifications on form submissions, order updates, and more.
Steps:
- Create custom WordPress plugin file
- Add SMS settings page in WP Admin
- Implement SMS sending via wp_remote_post
- Hook into WooCommerce order events
- Test SMS notifications
Code Sample:
<?php
/*
Plugin Name: OnlineSMSService Gateway
Description: Integrate SMS gateway with WordPress
Version: 1.0
*/
class SMSGatewayPlugin {
public function __construct() {
add_action("admin_menu", [$this, "add_menu"]);
}
public function send_sms($to, $message) {
return wp_remote_post(
"https://api.onlinesmsservice.com/v1/send",
[
"headers" => [
"Content-Type" => "application/json",
"Authorization" => "Bearer " .
get_option("sms_api_key")
],
"body" => json_encode([
"to" => $to,
"message" => $message,
"type" => "transactional"
])
]
);
}
}
new SMSGatewayPlugin();
Laravel Integration
Integrate SMS gateway with Laravel using a custom service provider. Leverage facades, dependency injection, and queue workers.
Steps:
- Create SMS service provider
- Register service in config/services.php
- Create SMS notification channel
- Implement via Laravel Notifications
- Add to Laravel queue system
Code Sample:
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class SMSService
{
public function send($to, $message, $type = "transactional")
{
$response = Http::withHeaders([
"Authorization" => "Bearer " . config("sms.api_key")
])->post(config("sms.base_url") . "/send", [
"to" => $to,
"message" => $message,
"type" => $type
]);
if ($response->successful()) {
return $response->json();
}
throw new \Exception("SMS failed: " . $response->body());
}
}
Additional Resources
API Documentation
Complete API reference with all endpoints, parameters, and response formats.
View Docs →SDK Downloads
Official SDKs for PHP, Node.js, Python, and other popular programming languages.
Get SDKs →DLT Registration
Step-by-step guide to DLT registration and TRAI compliance for commercial SMS.
DLT Guide →Support
Need help with integration? Our support team is available 24/7 to assist you.
Get Support →Ready to Start Integrating?
Get your free API key and start sending SMS in minutes. Our developer-friendly API makes integration effortless.