WhatsApp us

How to Send WhatsApp Messages Using Infobip API in PHP

  • Tech Area
  • Last updated on: January 8, 2026



Sending WhatsApp messages programmatically is essential for businesses that want to automate notifications, alerts, and customer communication. In this guide, you’ll learn how to send WhatsApp messages using the Infobip API with PHP, including account setup, API configuration, and a working code example.

Files used in this tutorial:

1- connection.php (database connection file)

2- index.php

File Structure with Infobip API PHP Client

Infobip WhatsApp API

Installation Infobip APIs Client Library for PHP

Infobip APIs client library can be installed with Composer. Run this command in your project root to install this library:

composer require infobip/infobip-api-php-client

Step 1: Create a Database connection

In this step, create a new file connection.php to create database connection.

connection.php

<?php
$server = "localhost";
$username = "root";
$password = "";
$database = "whatsapp_db";
$connection = mysqli_connect($server,$username,$password);
$select_db = mysqli_select_db($connection, $database);
if(!$select_db)
{
	echo("connection terminated");
}
?>

Step 2: Create index.php file

<html>  
<head>  
    <title>Send WhatsApp Message using PHP</title>  
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>  
</head>
<style>
 .box
 {
  width:100%;
  max-width:600px;
  background-color:#f9f9f9;
  border:1px solid #ccc;
  border-radius:5px;
  padding:16px;
  margin:0 auto;
 }
</style>
<?php
use Infobip\Configuration;
use Infobip\Api\WhatsAppApi;
use Infobip\Model\WhatsAppTextMessage;
use Infobip\Model\WhatsAppTextContent;

require 'vendor/autoload.php';
require 'connection.php';
if(isset($_POST['send_sms']))
{
  $number = $_POST['phone'];
  $msg = $_POST['msg'];

$configuration = new Configuration(
        host: 'e1mmwr.api.infobip.com',
        apiKey: 'YOUR-API-KEY'
    );
$whatsAppApi = new WhatsAppApi(config: $configuration);
$textMessage = new WhatsAppTextMessage(
        from: 'From-Number',
        to: $number,
        content: new WhatsAppTextContent(
            text: $msg
        )
    );

    $whatsAppApi = new WhatsAppApi(config: $configuration);
    
    $messageInfo = $whatsAppApi->sendWhatsAppTextMessage($textMessage);
    $insert_query = mysqli_query($connection, "insert into tbl_msg set phone_no='$number', message='$msg'");
    if($insert_query>0)
    {
      echo "<script>
      alert('Data Submitted.')</script>";
    }
  }
?>
<body>  
    <div class="container">  
    <div class="table-responsive">  
    <h3 align="center">Send WhatsApp Message using PHP</h3>
    <form method="post">
     <div class="box">
      <div class="form-group">
       <label for="phone">Enter Your Mobile Number</label>
       <input type="text" name="phone" id="phone" placeholder="Enter Mobile Number" class="form-control" required/>
      </div>        
      <div class="form-group">
       <label for="message">Enter Your Message</label>
       <textarea name="msg" id="msg" placeholder="Your Message" required class="form-control" rows="4"></textarea> 
      </div>
      <div class="form-group">
       <input type="submit" id="send_sms" name="send_sms" value="Send" class="btn btn-success" />
       </div>
     </div>
   </form>
   </div>  
  </div>
 </body>  
</html>

The screenshot below displays the user interface where users can enter their mobile number and message.

Download Source Code


Subscribe us via Email

Join 20,000+ subscriber

Subscribe on YouTube

PHP Projects
Matrimonial Portal Project in PHP & MySQL Last Updated: December 22, 2025
Event Management System Project in PHP & MySQL Last Updated: December 6, 2025
Online Shopping System Project in PHP MySQL Last Updated: November 26, 2025
Hostel management system project in PHP and MySQL Last Updated: February 14, 2024
Online Pizza Delivery project in PHP Last Updated: February 4, 2024
Parking Management System project in PHP Last Updated: November 5, 2023
Visitors Management System project in PHP Last Updated: August 28, 2023
SNIPE – IT Asset management system v6.1.0 Last Updated: April 21, 2023
Employee Management System project in PHP Last Updated: January 21, 2023