How to send a WhatsApp message with PHP
Send text and media messages from PHP with a single HTTP request, then receive replies on your own webhook. Plain REST and JSON — no SDK, no template approval.
Last updated:
- PHP
- REST + JSON
- no SDK needed
- webhook replies
<?php
$pid = "your-pid";
$phoneId = "your-phone-id";
$token = "your-token";
$ch = curl_init("https://api.maytapi.com/api/$pid/$phoneId/sendMessage");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["x-maytapi-key: $token", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"to_number" => "1415xxxxx67",
"type" => "text",
"message" => "Hello from PHP!",
]),
]);
echo curl_exec($ch);What you need
Four things, all available in the console within a few minutes.
-
account
A Maytapi account
Sign up and start the free trial — no card required.
-
phone
A paired number
Scan the QR code with WhatsApp on your phone. Your number keeps working as usual.
-
token
pid and token
Copy them from the token page of the console; phone_id is shown next to your number.
-
PHP
A PHP environment
Any recent PHP version with its standard HTTP client is enough.
Send a text message with PHP
POST a JSON body to /sendMessage with your token in the x-maytapi-key header. The message is queued on your phone and the response returns immediately.
- ✓to_number in international format, e.g. 1415xxxxx67
- ✓type: text and the message body
- ✓The response contains the message id
curl -X POST "https://api.maytapi.com/api/$PID/$PHONE_ID/sendMessage" \
-H "x-maytapi-key: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"to_number": "1415xxxxx67", "type": "text", "message": "Hello from PHP!"}'{
"success": true,
"data": {
"chatId": "1415xxxxx67@c.us",
"msgId": "3EB065B353B9493D00C9"
}
}Send an image, video or document
Use the same endpoint with type media and a public file URL or a base64 data URI. Add an optional caption and file name.
- ✓Images, video, audio, PDF and other documents
- ✓Caption in the text field
- ✓Base64 data URIs work as well as URLs
$ch = curl_init("https://api.maytapi.com/api/$pid/$phoneId/sendMessage");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["x-maytapi-key: $token", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"to_number" => "1415xxxxx67",
"type" => "media",
"message" => "https://example.com/invoice-10482.pdf",
"text" => "Your invoice for order #10482",
"filename" => "invoice-10482.pdf",
]),
]);
echo curl_exec($ch);Receive replies with a PHP webhook
Register a webhook URL once. Incoming messages, delivery and read receipts arrive as JSON; answer through the reply URL included in each event.
- ✓Return 200 quickly, then process the event
- ✓Skip your own messages with fromMe
- ✓Use event.reply to answer in the same chat
$ch = curl_init("https://api.maytapi.com/api/$pid/setWebhook");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["x-maytapi-key: $token", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode(["webhook" => "https://example.com/maytapi/webhook"]),
]);
echo curl_exec($ch);<?php
// webhook.php
$event = json_decode(file_get_contents("php://input"), true);
http_response_code(200);
if (($event["type"] ?? "") === "message" && !$event["message"]["fromMe"]) {
$ch = curl_init($event["reply"]);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["x-maytapi-key: $token", "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode([
"to_number" => $event["conversation"],
"type" => "text",
"message" => "Thanks! We received your message.",
]),
]);
curl_exec($ch);
}PHP WhatsApp API FAQ
Ask our support team anything over WhatsApp. Average response time is under 24 hours.
Help center →Is there an official PHP SDK?
You do not need one. The API is plain REST with JSON, so the standard PHP HTTP client is enough, as the examples on this page show.
Can I send messages to groups from PHP?
Yes. Use the group id (ending in @g.us) as to_number; group management endpoints are available on every plan.
Why did my message not arrive?
Check that the phone status is active, then look at the queue and logs in the console. New numbers should be warmed up before sending in volume.
More WhatsApp API features

Get your key, send your first message in ten minutes
No approval, no templates, no card. Every endpoint is open for three days.