whatsapp-api-php

Send a Message by WhatsApp API using PHP

In this tutorial, we will create a page to send messages via WhatsApp API using PHP

Before starting, an active account is required (If Not Register Your Account), Login to your account & get your secret API_KEY

First of all we will create a file name function.php, having the following code

<?php
function wa($mobile = null, $type = null, $message = null, $priority = null){
$api_key='';////YOUR_API_KEY

$curl = curl_init();
$url = "http://whatsapp247.com/api/send.php";
if($type=='1' || $type=='2'){
$parameters = array("api_key" => $api_key, "type" => $type, "mobile" => $mobile, "url" => $message, "priority" => $priority);}else{
$parameters = array("api_key" => $api_key, "type" => $type, "mobile" => $mobile, "message" => $message, "priority" => $priority);    
}
$ch = curl_init();
$timeout  =  30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$response = curl_exec($ch);
curl_close($ch);
return $response ;
}
?>

In line no 3, paste your secret API key

include this file in your PHP page

require_once('function.php'); 

Send Text Message

echo wa('923XXXXX', '0', 'Hello World', '10');
Parameters Description: Refference

Send Image Message

echo wa('923XXXXX', '1', 'https://sample-videos.com/img/Sample-jpg-image-50kb.jpg', '10');

Send Document Message

echo wa('923XXXX', '2', 'https://www.africau.edu/images/default/sample.pdf', '10');

Send Audio / Voice Message

echo wa('923XXXX', '2', 'https://file-example.s3-accelerate.amazonaws.com/voice/oog_example.ogg', '10');

Download Sample Code: Download


For More Details, Please Visit Our WhatsApp API Documentation

Related Posts