Simple WhatsApp Messages Send Using Chat API In PHP; We will send WhatsApp messages using chat API in PHP but before that, we need to generate the instance and token no from the chat API. For that, you need to create an account in the chat API, after that, they will provide the token no and instance number for sending a message to WhatsApp.
Using chat API we will send WhatsApp messages, for that, we will create an account, click on the given link and create an account Create Account
See below the given image, from there you will find your credentials.
Integrate In PHP
Once you generate your token and instance number from there, paste in the given variable $token & $instanceId, then after adding your mobile number to the data array define the template name as well as the namespace and language also.
Now run your PHP script and you will receive a message from the register number in the account.
<?php $data = [ 'phone' => '+91XXXXXXXXXX', // RECEIVERS PHONE 'template' => 'template_name', // TEMPLATE NAME 'namespace' => 'namespace_of_template', // NAMESPACE OF TEMPLATE 'language' => ['code' => 'en', 'policy' => 'deterministic'], // LANGUAGE PARAMETERS ]; $json = json_encode($data); // ENCODE DATA TO JSON // URL FOR REQUEST POST /MESSAGE $token = 'YOUR TOKEN'; $instanceId = 'YOUR INSTANCE NUMBER'; $url = "https://api.chat-api.com/instance{$instanceId}/sendTemplate?token={$token}"; // MAKE A POST REQUEST $options = stream_context_create(['http' => [ 'method' => 'POST', 'header' => 'Content-type: application/json', 'content' => $json ] ]); // SEND A REQUEST $result = file_get_contents($url, false, $options);
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- PHP Post Request cURL Example With Authentication
- How To Check Given URL Is Valid Or Not PHP Function Example
- Get Zipcode/Pincode From Latitude and Longitude PHP and Google Maps API
- UPI Payment Gateway Integration in PHP/Laravel
- Get IP PHP Function Example - ip_info()
- PhonePe Payment Gateway Example PHP
- How To Get Youtube Video Thumbnail From URL In PHP - Laravel
- How To Add Google reCAPTCHA v2 In HTML Form Based PHP/Laravel Website
- Timestamp convert to datetime format
- Upayments Gateway Integration PHP - Laravel