Home › Guides › Developers

How to send WhatsApp messages from PHP using a REST API

By the OmegaAPI team · Updated 19 November 2026 · 7 min read

Many Indian businesses want their website to send an order confirmation, appointment reminder or login code to a customer on WhatsApp. This guide shows a working PHP example using the Omega Messaging Gateway REST API, where you link your own number by scanning a QR code and then call simple HTTP endpoints.

OmegaAPI is not affiliated with Meta or WhatsApp. For very high volume marketing to people who have not messaged you first, Meta's official WhatsApp Business Platform is the right tool. The method below suits transactional messages to your own customers.

1. What you need

  • A free OmegaAPI account and an active Messaging Gateway plan.
  • A phone number you control, linked from your panel by scanning the QR code (the same way you link WhatsApp Web).
  • Your API key from the panel. It starts with wag_. Keep it on the server only — never in JavaScript that runs in the browser.
  • PHP 7.4 or newer with the cURL extension (enabled on almost every hosting plan).

2. Send one message

The endpoint is POST https://omegaapi.in/api/v1/send-text. Send JSON with the number in international format without the plus sign (India: 91 + 10 digits).

<?php
function omega_send($to, $message, $agentId = null) {
    $payload = ['to' => $to, 'message' => $message];
    if ($agentId) $payload['agentId'] = $agentId;
    $ch = curl_init('https://omegaapi.in/api/v1/send-text');
    curl_setopt_array($ch, [
        CURLOPT_POST           => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 20,
        CURLOPT_HTTPHEADER     => [
            'X-API-Key: ' . getenv('OMEGA_API_KEY'),
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS     => json_encode($payload),
    ]);
    $body = curl_exec($ch);
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return [$code, json_decode($body, true)];
}

[$code, $res] = omega_send('919876543210', 'Hi Ravi, your order #1045 has been shipped.');
if ($code === 200 && !empty($res['ok'])) {
    echo "Sent";
} else {
    error_log("Message failed: HTTP $code " . json_encode($res));
}

Store the key in an environment variable or a config file outside public_html, not in the code you commit.

3. Send the same message to many numbers

Use POST /api/v1/send-bulk. The request is accepted at once (HTTP 202) and messages go out in the background with a short random gap between them, which looks more natural than a burst.

$ch = curl_init('https://omegaapi.in/api/v1/send-bulk');
curl_setopt_array($ch, [
    CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('OMEGA_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode([
        'recipients' => ['919876543210', '919812345678'],
        'message'    => 'Our shop is closed tomorrow for Diwali. Happy Diwali!',
    ]),
]);
$res = json_decode(curl_exec($ch), true);
// $res['batchId'] — check progress later at GET /api/v1/bulk/{batchId}

4. Handle errors properly

  • 401 — wrong or missing API key.
  • 400 — bad input, or the number is not on WhatsApp.
  • 402 — message credits used up or plan expired.
  • 409 — no linked number is online right now; open the panel and re-scan if needed.
  • 429 — too many requests or the daily per-number limit reached; retry later.

Never retry in a tight loop. Log the failure, and retry after a few minutes at most once or twice.

5. Keep your number healthy

  • Message only people who gave you their number and expect to hear from you (customers, leads who asked).
  • Make every message useful and personal — include the name and the order or booking it is about.
  • Give an easy way to stop messages ("Reply STOP") and respect it.
  • Start slowly with a new number. Sudden large sends to strangers are the main reason numbers get restricted.

Full endpoint reference: API documentation. To receive replies and OTPs, read how to verify webhook signatures.

Frequently asked questions

Can I send WhatsApp messages from PHP without the official Business API?

Yes, by linking your own number as a linked device and using a gateway API like this one. It is meant for transactional messages to your own customers; for large opt-in marketing campaigns use Meta's official platform.

Which number format should I use?

Country code followed by the number, without + or spaces. For India: 91 followed by the 10-digit mobile number, for example 919876543210.

Does my phone have to stay on?

No. The linked-device session keeps working when the phone is off for a while. If you log out of linked devices on the phone, scan the QR code again.

More guides