Send Automated WhatsApp Messages Using PHP The Ultimate Guide

December 2, 2024

Today, we’ll show you the ultimate guide for sending different types of WhatsApp automated messages using PHP with ready-to-use code examples that you can easily integrate into your existing code base.

Effective communication is vital for project coordination, community engagement, and responsive customer support. Wassenger enhances this process by providing seamless management and interaction tools within WhatsApp messages. With its intuitive API and automation features, sending messages, videos, images, documents, and voice memos becomes simple and efficient.

In this article you will find:

  • Send Image Message 🖼️
  • Send Video Messages 📹
  • Send Document Messages 📄
  • Send Audio Voice Record 🎙️
  • Send a Media Message with an Uploaded File 📤
  • Send a GIF Message 🎞️
  • Send a Poll Message 📊
  • Send a Scheduled Date and Time Message 📅
  • Send Dynamic Native Button Messages 🔘
  • Send a List of Items to Select From 📝
  • Send a Message with Text Formatting ✍️
  • Send a Location Message with Coordinates 📍
  • Send a Location Message with the Address 🗺️
  • Send a Message with Variables 🔄
  • Send Messages with Links 🔗
  • Send Contact Card Messages 📇
  • Reply to a Message 💬
  • Forward a Message 🔁
  • Send a Catalogue Message 📒
  • Send a Message in Real-Time with No Enqueueing ⏱️
  • Send a Message with Maximum Retries 🔄
  • Send a Message with the Expiration Time ⏳
  • Send a Message Within a Time and Day Range 🕰️
  • Send a Message Reaction 😊
  • Remove a Message Reaction 🚫
  • Send a Message on Behalf of an Agent and Assign a Chat 👤
  • Send a Message and Resolve the Chat ✅
  • Send a Message and Add a Chat Label 🏷️

🤩 🤖 Wassenger is a complete communication platform and API solution for WhatsApp. Explore more than 100+ API use cases and automate anything on WhatsApp by signing up for a free trial and getting started in minutes!

Requirements

  • To have a WhatsApp number linked to the Wassenger: it takes 2 minutes and you can use your existing number, sign up for free here!
  • Message recipient phone number with international prefix in E164 format. Example: +12345678900. Validate the phone number format here.
  • PHP 6 or higher installed on your computer
  • Install HTTP client package by running: pecl install pecl_http

API endpoint

We will use the following API endpoint to send messages to a group:

Prepare the request

Target API URL using the POST method

https://api.wassenger.com/v1/messages

Required HTTPS headers > Obtain your API key here

Content-Type: application/json
Token: $API_TOKEN

Use body in JSON format

{
  "phone": "+1234567890",
  "message": "Hello world, this is a sample message"
}

🖥️ Looking for a code example? Go to the API live tester and get ready-to-use code examples in 15+ programming languages, including JavaScript, PHP, C#, Java, Ruby, Go, Powershell, cURL and more.

Send text messages with PHP

// Examples requires to have installed pecl_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl_http // More information: https://mdref.m6w6.name/http

append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Hello world, this is a sample message' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); > 🤩 🤖 [**Wassenger**](https://wassenger.com/) is a complete API solution for WhatsApp. [**Sign up for a 7-day free trial and get started in minutes!**](https://wassenger.com/register) #### More examples of sending messages with PHP For full samples, visit our [API Live Tester](https://app.wassenger.com/help/api-tester) [**Send image message with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a caption for an image message', 'media' => \[ 'url' => 'https://picsum.photos/seed/picsum/600/400', 'expiration' => '7d', 'viewOnce' => null \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send video messages with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a caption for a video message', 'media' => \[ 'url' => 'https://download.samplelib.com/mp4/sample-5s.mp4', 'expiration' => '7d' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)\->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send document messages with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'media' => \[ 'url' => 'https://www.africau.edu/images/default/sample.pdf', 'expiration' => '30d' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send audio voice record with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'media' => \[ 'url' => 'https://download.samplelib.com/mp3/sample-9s.mp3', 'format' => 'ptt' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a media message with an uploaded file using PHP**](https://app.wassenger.com/help/api-tester) > `*{{UPLOADED FILE ID}}*` : Replace this expression with the specific value - You can upload the file [**here**](https://app.wassenger.com/files) - The **file ID** will look something like this: **57443b8773c036f2bae0cd96** // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a caption for an image message', 'media' => \[ 'file' => '{{UPLOADED FILE ID}}' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a GIF message with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a sample caption for a GIF message', 'media' => \[ 'url' => 'https://i.giphy.com/vKHKDIdvxvN7vTAEOM.mp4', 'format' => 'gif' \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a poll message with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'poll' => \[ 'name' => 'Vote for your favorite color', 'options' => \[ 'Red', 'Green', 'Blue', 'Yellow', 'Grey', 'Black', 'Orange', 'Purple', 'White' \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a scheduled date and time message with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a scheduled message to be sent to a phone number in 10 minutes', 'deliverAt' => '2024-12-02T13:52:32.396Z' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send dynamic native button messages with PHP**](https://app.wassenger.com/help/api-tester) WhatsApp no longer accepts native button messages. Buttons messages will be automatically converted into raw text equivalent messages. [Learn more here](https://app.wassenger.com/updates/v1.9.4) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This is a message with dynamic reply buttons', 'header' => 'Optional message header', 'footer' => 'Optional message footer', 'buttons' => \[ \[ 'id' => 'id1', 'text' => 'Say hello' \], \[ 'id' => 'id2', 'text' => 'Say goodbye' \], \[ 'id' => 'id3', 'text' => 'Get help' \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a list of items to select from with PHP**](https://app.wassenger.com/help/api-tester) WhatsApp no longer accepts list messages. List messages will be automatically converted into raw text equivalent messages. [Learn more here](https://app.wassenger.com/updates/v1.9.4) '+1234567890', // Recipient's phone number 'list' => \[ 'button' => 'Select one option', 'description' => 'Select which type of vehicle you are interested in', 'title' => 'Motor Business', 'footer' => 'Since 1990', 'sections' => \[ \[ 'title' => 'Select a car type', 'rows' => \[ \['title' => 'Coupe', 'id' => 'a1', 'description' => 'Description for coupe cars'\], \['title' => 'Sports', 'id' => 'a2', 'description' => 'Description for sports cars'\], \['title' => 'SUV', 'id' => 'a3', 'description' => 'Description for SUV cars'\], \['title' => 'Minivan', 'id' => 'a4', 'description' => 'Description for minivan cars'\], \['title' => 'Crossover', 'id' => 'a5', 'description' => 'Description for crossover cars'\], \['title' => 'Wagon', 'id' => 'a6', 'description' => 'Description for wagon cars'\] \] \], \[ 'title' => 'Select a motorbike type', 'rows' => \[ \['title' => 'Touring', 'id' => 'b1', 'description' => 'Long-distance motorbikes'\], \['title' => 'Cruiser', 'id' => 'b2', 'description' => 'Harley-Davidson-style bikes'\], \['title' => 'Standard', 'id' => 'b3', 'description' => 'Street and commuter bikes'\] \] \] \] \] \]; // Set up the request body $body = new http\\Message\\Body; $body\->append(json\_encode($payload)); // Configure the HTTP request $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', // Set content type 'Token' => 'ENTER API KEY HERE' // Add your API key here \]); // Send the request $client\->enqueue($request)->send(); $response = $client\->getResponse(); // Output the response for debugging echo $response\->getBody(); [**Send a message with text formatting using PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'This message is formatted using \_italic format\_, \*bold format\*, ~strikethrough format~ and \`\`\`monospace format\`\`\`' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message with location coordinates using PHP**](https://app.wassenger.com/help/api-tester) [Learn more about how to send location messages with coordinates in this tutorial](https://app.wassenger.com/help/send-location) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'location' => \[ 'coordinates' => \[ 40.7583748, -73.9891184 \] \], 'message' => 'This is a location message using coordinates' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send location message with address using PHP**](https://app.wassenger.com/help/api-tester) [Learn more about how to send location messages with addresses in this tutorial](https://app.wassenger.com/help/send-location) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'location' => \[ 'address' => 'Santa Claus Main Post Office, Tähtikuja 1, 96930 Arctic Circle, Finland' \], 'message' => 'This is a location message using an address' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message with variables using PHP**](https://app.wassenger.com/help/api-tester) [Learn more about how to send messages with template variables in this tutorial.](https://app.wassenger.com/help/template) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Dear {{ contact.name | customer }}, Thanks for contacting us! We will answer your query shortly. Your message was received on {{ date.humanize.full }}' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message with a URL using PHP**](https://app.wassenger.com/help/api-tester) [Learn more about how to send messages with URL links in this tutorial](https://app.wassenger.com/help/send-links) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Check out this cool link: https://www.youtube.com' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send contact card messages with PHP**](https://app.wassenger.com/help/api-tester) [Learn more about how to send contact card messages in this tutorial](https://app.wassenger.com/help/send-contacts) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'contacts' => \[ \[ 'phone' => '+1234567890', 'name' => 'John Doe' \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Reply to a message with PHP**](https://app.wassenger.com/help/api-tester) `{{MESSAGE ID}}` : Replace with the actual WhatsApp message ID to forward (18, 20, 22 or 32 hexadecimal value) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'quote' => '{{MESSAGE ID}}', 'message' => 'This message is a reply to another message within the same chat' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Forward a message with PHP**](https://app.wassenger.com/help/api-tester) `{{MESSAGE ID}}` : Replace with the actual WhatsApp message ID to reply to (18, 20, 22 or 32 hexadecimal value) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'forward' => \[ 'message' => '{{MESSAGE ID}}', 'chat' => '+1234567890' \], 'message' => 'The given message by ID will be forwarded to another chat' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a catalogue message with PHP**](https://app.wassenger.com/help/api-tester) `{{PRODUCT CATALOG ID TO SEND}}` : Replace this expression with the specific value // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'product' => '{{PRODUCT CATALOG ID TO SEND}}' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message in real-time with no enqueueing using PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'live' => null, 'phone' => '+1234567890', 'message' => 'This message will be delivered in real-time if the session is online, otherwise the API will return an error' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message with maximum retries using PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'retries' => 2, 'phone' => '+1234567890', 'message' => 'This message will be retried only twice. If the delivery fails twice, it will be flagged as deleted message, removed from the queue and not delivered' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message with the expiration time using PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'expiration' => \[ 'seconds' => 90 \], 'phone' => '+1234567890', 'message' => 'This message will be deleted if it cannot be delivered within 90 seconds after being queued. This is useful to guarantee time-sensitive messages are not delivered later than required.' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); > *🤩 🤖* [***Wassenger***](https://wassenger.com/) *is a complete API solution for WhatsApp.* [***Sign up for a 7-day free trial and get started in minutes!***](https://wassenger.com/register) [**Send a message within a time and day range using PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Restricted message example that will be only delivered between 9 am to 5 pm from Monday to Friday. If the message cannot be delivered within those time ranges, it will wait in the queue', 'restrict' => \[ 'start' => 9, 'end' => 17, 'timezone' => 'CEST', 'weekdays' => \[ 1, 2, 3, 4, 5 \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message reaction using PHP**](https://app.wassenger.com/help/api-tester) `{{WHATSAPP MESSAGE ID}}` : Replace this expression with the specific value // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'reaction' => '👍', 'reactionMessage' => '{{WHATSAPP MESSAGE ID}}' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); Remove message reaction: `{{WHATSAPP MESSAGE ID}}` : Replace this expression with the specific value // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'reaction' => '-', 'reactionMessage' => '{{MESSAGE WHATSAPP ID}}' \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message on behalf of an agent and assign a chat using PHP**](https://app.wassenger.com/help/api-tester) `{{USER ID}}` : Replace with the actual user ID (24 hexadecimal value) `{{ASSIGNED USER ID}}` : Replace with the actual user ID to assign the chat (24 hexadecimal value) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'agent' => '{{USER ID}}', 'message' => 'This message is sent via API on behalf of an agent. The chat will also be assigned to the agent after message delivery.', 'actions' => \[ \[ 'action' => 'chat:assign', 'params' => \[ 'agent' => '{{ASSIGNED USER ID}}' \] \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message and resolve the chat with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Once this message is delivered, the chat will be reported as resolved in the web chat interface.', 'actions' => \[ \[ 'action' => 'chat:resolve' \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); [**Send a message and add a chat label with PHP**](https://app.wassenger.com/help/api-tester) // Examples requires to have installed pecl\_http package, a simple and elegant HTTP client for PHP. // Install it by running: pecl install pecl\_http // More information: https://mdref.m6w6.name/http append(json\_encode(\[ 'phone' => '+1234567890', 'message' => 'Once this message is delivered, the given labels will be added to the chat automatically.', 'actions' => \[ \[ 'action' => 'labels:add', 'params' => \[ 'labels' => \[ 'new', 'sales' \] \] \] \] \])); $request\->setRequestUrl('https://api.wassenger.com/v1/messages'); $request\->setRequestMethod('POST'); $request\->setBody($body); $request\->setHeaders(\[ 'Content-Type' => 'application/json', 'Token' => 'ENTER API KEY HERE' \]); $client\->enqueue($request)->send(); $response = $client\->getResponse(); echo $response\->getBody(); > *🤩 🤖* [***Wassenger***](https://wassenger.com/) *is a complete API solution for WhatsApp.* [***Sign up for a 7-day free trial and get started in minutes!***](https://wassenger.com/register) #### Live API testing [You can live-test and play with the API directly from your browser in minutes.](https://app.wassenger.com/help/api-tester) Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go. ![](/images/blog/send-automated-whatsapp-messages-using-php-02.png) ### FAQ #### How to send messages to multiple phone numbers You have to send multiple API requests, one per target phone number. For instance, to send a message to 10 phone numbers, you should send 10 independent HTTPS requests to the API. There is no option to send multiple messages in a single API request. #### How to validate if a phone number can receive WhatsApp messages You can validate if a given phone number is linked to a WhatsApp account and can receive messages. The [API provides an endpoint](https://app.wassenger.com/docs/#operation/numberExists) that can validate whether a given phone number exists in WhatsApp or not. The only requirement is to have at least one WhatsApp number connected to the platform in your current account. For more details, please check out the [API endpoint documentation here](https://app.wassenger.com/docs/#operation/numberExists). Before you check if a phone number exists on WhatsApp, you can also validate and normalize the format of a list of phone numbers by using the [numbers validator API endpoint](https://app.wassenger.com/docs#operation/validateNumbers). This endpoint only validates the correct [E164 format](https://en.wikipedia.org/wiki/E.164), but it does not check whether the phone number effectively exists on WhatsApp. Note: The number of WhatsApp check validations is limited per month based on your subscription plan. Please check out the [pricing table](https://app.wassenger.com/pricing) for more details about the limits. > ***Looking for more answers?*** [***Check out the extended FAQs***](https://app.wassenger.com/help/category/faq)***.*** #### Further useful resources #### API Documentation For more details about the endpoint API, please check the documentation where you will find all the details about the accepted request params, possible success or error responses and ready-to-use code examples in multiple programming languages: [https://app.wassenger.com/docs/#tag/Messages/operation/createMessage](https://app.wassenger.com/docs/#tag/Messages/operation/createMessage)

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free