Automate WhatsApp Messages Using PHP

April 1, 2025

Take your customer communication to the next level by sending automated WhatsApp messages with PHP and the Wassenger API. Whether it’s reminders, personalized offers, or promo updates, reach your audience at the right time, every time.

In this guide, we’ll walk you through how to connect PHP with Wassenger to streamline your messaging, improve engagement, and drive more sales. It’s a simple setup with big results perfect for businesses looking to automate and grow.

🫣 Don’t want to use programming? No problem! Explore our new no-code WhatsApp Campaigns feature. Import your contacts, define a message, set a delivery date and relax! 🥳 🥳

🤩 🤖 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 already linked to the platform and online.
  • Message recipient phone number with international prefix in E164 format. Example: +12345678900. Validate the phone number format here.

API endpoint

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

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 Python, JavaScript, PHP, C#, Java, Ruby, Go, Powershell, cURL and more.

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Send automated messages with PHP (Guzzle)

  • 🔑 Setup: The API key, phone number, and message are stored in variables.
  • 🛠️ Client and Request: An http\Client and an http\Client\Request are instantiated.
  • 📝 Body: The message body is created as a JSON object and appended to the request body.
  • 🔒 Headers: Headers for Content-Type and Token are added to the request.
  • 📤 Sending the Request: The request is enqueued and sent. The response is checked for success, and appropriate messages are printed based on the response status.
// This code example requires to have installed Guzzle package, a flexible and elegant HTTP client for PHP.
// Install it first following these instructions:
// https://docs.guzzlephp.org/en/stable/overview.html#installation
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.wassenger.com/v1/messages', [
  'body' =>
    '{"phone":"+12345678909", "message":"Hello world, this is a sample message"}',
  'headers' => [
    'Content-Type' => 'application/json',
    'Token' => 'API TOKEN GOES HERE',
  ],
]);
echo $response->getBody();

Send automated messages with PHP (http2)

  • 🔑 Setup: The API key, phone number, and message are stored in variables.
  • 🛠️ Client and Request: An http\Client and an http\Client\Request are instantiated.
  • 📝 Body: The message body is created as a JSON object and appended to the request body.
  • 🔒 Headers: Headers for Content-Type and Token are added to the request.
  • 📤 Sending the Request: The request is enqueued and sent. The response is checked for success, and appropriate messages are printed based on the response status.
// This code example 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
<?php
$client = new http\Client();
$request = new http\Client\Request();
$body = new http\Message\Body();
$body->append(
  json_encode([
    'phone' => '+12345678909',
    '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' => 'API TOKEN GOES HERE',
]);
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Send automated messages with PHP (curl)

  • 📲 Dynamic Variables: The API key, phone number, and message are stored in variables.
  • ⚙️ cURL Setup: curl_setopt_array is used to configure the cURL options, including the URL, headers, request method, and request body.
  • 💻 JSON Encoding: The payload is created using json_encode to incorporate dynamic variables.
  • ⚠️ Execution and Error Handling: curl_exec executes the request, and any errors are captured with curl_error. The response or error is then printed.
<?php
$curl = curl_init();
curl_setopt_array($curl, [
  CURLOPT_URL => 'https://api.wassenger.com/v1/messages',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => json_encode([
    'phone' => '+12345678909',
    'message' => 'Hello world, this is a sample message',
  ]),
  CURLOPT_HTTPHEADER => [
    'Content-Type: application/json',
    'Token: API TOKEN GOES HERE',
  ],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
  echo 'cURL Error #:' . $err;
} else {
  echo $response;
}

🤩 🤖 Wassenger is a complete API solution for WhatsApp. Sign up for a 7-day free trial and get started in minutes!

Live API testing

You can live-test and play with the API directly from your browser.

Once you are done testing, get the auto-generated code example in your preferred programming language and you will be ready to go.

Try our API-Live tester now

🤩 🤖 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!

FAQ

Can I use Wassenger to send marketing messages?

As you may know, WhatsApp has strict policies about sending unsolicited marketing messages, illicit content or spam.

Sending marketing or any unsolicited messages to users is not allowed and you would put your WhatsApp number at a high risk of getting banned.

WhatsApp communication is not suitable for all business cases, so we recommend designing a legitimate and user-approved communication strategy to avoid any problems.

Please read our guidelines with communication best practices and how to prevent getting banned.

How to send messages to multiple phone numbers 📲

You have to send numerous 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 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.

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. This endpoint only validates the correct E164 format, 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 for more details about the limits.

Looking for more answers? Check out the extended FAQs.

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

Ready to transform your WhatsApp communication?

Start automating your customer interactions today with Wassenger

Get Started Free