Back to Blog List
HomeBlogHow to Send SMS from PHP, Node.js and Laravel in Sri Lanka (2026 Guide)
DevelopersAPI

How to Send SMS from PHP, Node.js and Laravel in Sri Lanka (2026 Guide)

SMSGo Team July 7, 2026 6 min read
How to Send SMS from PHP, Node.js and Laravel in Sri Lanka (2026 Guide)

For modern web and mobile applications in Sri Lanka, sending transactional updates, order confirmations, and one-time passwords (OTP) via SMS is essential. In this step-by-step developer's guide, we will explore how to integrate the SMSGo REST API into PHP, Node.js, and Laravel applications to send SMS messages across Dialog, Mobitel, Hutch, and Airtel numbers.

Prerequisites

Before you begin, ensure you have the following:

  • An active account on SMSGo.lk. If you don't have one, register for free.
  • Your API key, which you can generate instantly from the developer settings dashboard.
  • An approved sender mask (your brand name). You can submit a request for a custom sender mask through your portal.

1. Sending SMS with PHP (cURL)

Using raw PHP, you can initiate a standard cURL POST request to submit a JSON payload. Below is a copy-pasteable example of how to make an authenticated request to our API endpoint:

<?php
$apiKey = "YOUR_API_KEY";
$recipient = "94771234567"; // Receiver's number in international format
$message = "Hello from SMSGo! Your verification code is 492019";
$mask = "SMSGO"; // Your approved sender mask

$ch = curl_init("https://api.smsgo.lk/api/v1/sms/send");
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "X-API-Key: " . $apiKey,
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "to" => $recipient,
        "message" => $message,
        "mask" => $mask,
        "campaignName" => "PHP-API"
    ]),
]);

$response = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo 'Response: ' . $response;
}
curl_close($ch);
?>

2. Sending SMS with Node.js (fetch)

In modern Node.js environments (v18+), you can use the built-in fetch API to make asynchronous JSON calls:

const apiKey = 'YOUR_API_KEY';
const payload = {
  to: '94771234567',
  message: 'Your SMSGo verification code is 492019',
  mask: 'SMSGO',
  campaignName: 'Node-API'
};

fetch('https://api.smsgo.lk/api/v1/sms/send', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': apiKey
  },
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(data => console.log('Response:', data))
  .catch(err => console.error('Error:', err));

3. Sending SMS from Laravel

If you are building a Laravel application, you can leverage Laravel's robust Http client. First, store your API credentials in your .env file:

SMSGO_API_KEY=YOUR_API_KEY
SMSGO_MASK=SMSGO

Then, create a helper class or directly invoke the request inside your controllers/jobs:

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;

class SmsController extends Controller
{
    public function sendSms()
    {
        $response = Http::withHeaders([
            'X-API-Key' => env('SMSGO_API_KEY'),
        ])->post('https://api.smsgo.lk/api/v1/sms/send', [
            'to' => '94771234567',
            'message' => 'Hello from Laravel! Your order has been shipped.',
            'mask' => env('SMSGO_MASK', 'SMSGO'),
            'campaignName' => 'Laravel-API'
        ]);

        if ($response->successful()) {
            return response()->json($response->json());
        }

        return response()->json(['error' => 'Failed to send SMS'], 500);
    }
}
?>

4. Sending OTP Codes

For security alerts and user signups, it is best to direct verification traffic over our prioritised channels. The integration remains identical to the examples above. Be sure to check out our detailed guide on OTP Verification in Sri Lanka for tips on reducing checkout fraud.

5. Character Encoding & Unicode SMS

A single SMS segment allows up to 160 English characters (GSM-7 encoding). However, when sending messages containing Sinhala or Tamil Unicode text, the limit per segment drops to 70 characters. Long messages will be split and concatenated by recipient mobile devices, which counts as multiple credits. Plan your messaging copy accordingly to stay cost-effective.

Conclusion

By using the code samples above, you can integrate SMSGo.lk into your applications and start sending messages immediately at the flat LKR 0.54 rate. For bulk setups, visit our Bulk SMS gateway page or review our full endpoint parameters in the REST API Documentation.

Implement this in your platform today

Integrate SMSGo's high-speed Sri Lankan SMS gateway API, set up secure OTP verification, or start bulk marketing campaigns.

Related Articles