Skip to main content

Prerequisites

Before you begin:

  • A SpringEdge account and API key (sign up free; the key is shared after sign-up, along with test credits)
  • PHP 7.4 or higher with the cURL extension enabled
  • A DLT-registered sender ID and an approved message template (needed for every SMS sent in India)

Zero Dependencies

PHP's built-in cURL extension is all you need

Simple HTTP API

One form-encoded POST (GET also works), with JSON or XML back

HTTPS + API Key

API key sent as a request parameter over TLS, with optional IP whitelisting

<?php
// send_sms.php
$url = 'https://web.springedge.com/api/web/send/';

$params = [
    'apikey'  => 'YOUR_API_KEY',
    'sender'  => 'SEDEMO',
    'to'      => '91XXXXXXXXXX',
    'message' => 'Your OTP is 482910',
    'format'  => 'json',
];

$ch = curl_init($url);
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    // http_build_query URL-encodes each value
    CURLOPT_POSTFIELDS     => http_build_query($params),
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_TIMEOUT        => 30,
]);

$response = curl_exec($ch);
if ($response === false) {
    // Timeout, DNS or SSL failure
    fwrite(STDERR, 'cURL error: ' . curl_error($ch) . "
");
    exit(1);
}

$result = json_decode($response, true);
if (!isset($result['MessageIDs'])) {
    // Errors come back as text, e.g. "Invalid Sender ID"
    fwrite(STDERR, 'Not sent: ' . trim($response) . "
");
    exit(1);
}

echo "Message ID: {$result['MessageIDs']}\n";

// Accepted (format=json):
// {"groupID": 61, "MessageIDs": "61-1",
//  "status": "AWAITED-DLR"}

PHP cURL

Basic PHP Example

The script posts five form fields to the SpringEdge SMS API, with your key in apikey. http_build_query URL-encodes the values, so spaces, & and Hindi text arrive intact. The message must match one of your DLT-approved templates word for word.

An accepted message returns JSON with a groupID and MessageIDs; save the message ID to match delivery reports. If the API can't send, it replies with a short text message such as Invalid Mobile Numbers or Insufficient Credits, and the script prints it and exits with status 1. All parameters are in the SMS API documentation.

Quick Start:

  1. Put your API key in place of YOUR_API_KEY
  2. Use your approved sender ID, a real mobile number and your template text
  3. Run: php send_sms.php
  4. Check the response for the MessageIDs value

LARAVEL

Laravel Service Class

In Laravel, keep the API call in one class under app/Services/. It returns the message ID, or throws with the API's reason so a queued job can retry. Call it from a controller, job or event listener:

app(SmsService::class)->send('91XXXXXXXXXX', 'Your OTP is 482910');

Put the key in .env as SPRINGEDGE_API_KEY and add 'springedge' => ['key' => env('SPRINGEDGE_API_KEY')] to config/services.php. It stays on the server; never send it to the browser.

<?php
// app/Services/SmsService.php
namespace App\Services;

use Illuminate\Support\Facades\Http;
use RuntimeException;

class SmsService
{
    private const URL = 'https://web.springedge.com/api/web/send/';

    /** Returns the message ID, e.g. "61-1". */
    public function send(string $phone, string $message): string
    {
        $response = Http::asForm()
            ->timeout(30)
            ->post(self::URL, [
                'apikey'  => config('services.springedge.key'),
                'sender'  => 'SEDEMO',
                'to'      => $phone,
                'message' => $message,
                'format'  => 'json',
            ]);

        $id = $response->json('MessageIDs');
        if ($response->failed() || !is_string($id)) {
            // Errors come back as text, e.g. "Insufficient Credits"
            throw new RuntimeException(
                'SMS not sent: ' . trim($response->body())
            );
        }

        return $id;
    }
}

What You Can Build

OTP Verification

Send a six-digit code at sign-up or login, store a hash with a 10-minute expiry, and compare it when the user types it in.

Order Notifications

Text the customer when an order is placed, packed and shipped. A D2C brand can also ask COD buyers to confirm before dispatch.

WordPress Plugins

Hook the cURL call into a WooCommerce order status action, or a Contact Form 7 or Gravity Forms submission, in a small custom plugin.

CRM Integration

Let your PHP-based CRM text a new lead within a minute of the enquiry, and remind the sales rep about follow-ups that are due.