How to Send and Receive Messages in WhatsApp using PHP
In this tutorial you will see How to Send and Receive Messages in WhatsApp using PHP.
Prerequisite :-
# Chat-API Token , Refer : https://www.phphive.info/255/get-whatsapp-password/
PHP Snippet for Sending Messages
Docs : http://chat-api.phphive.info/docs#/message/sendTextMessageRequest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php $chatApiToken = ""; // Get it from https://www.phphive.info/255/get-whatsapp-password/ $number = "919999999999"; // Number $message = "Hello :)"; // Message $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'http://chat-api.phphive.info/message/send/text', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS =>json_encode(array("jid"=> $number."@s.whatsapp.net", "message" => $message)), CURLOPT_HTTPHEADER => array( 'Authorization: Bearer '.$chatApiToken, 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; |
Sample Output :
1 2 3 4 5 6 7 |
{ "error":0, "response":{ "message":"Message sent successfully", "messageID":"string" } } |
For Receiving Messages
Refer : http://chat-api.phphive.info/docs#/device/messagesRequest
Q : Is There any Daily Limit for Using this API ?
Ans : No! There’s No Daily Limit. But Spamming is Obviously not allowed. We are keeping records of IP’s, if we find someone Spamming our Service then that IP will be Banned.
Chat-API Full Documentation available at http://chat-api.phphive.info/docs
Enjoy 🙂
Thanks!
Your feedback helps us to improve PHPHive.info
67 Comments
i m able to send message, but unable to receive message
You Need to Install PHP Protobuf and Curve25519 to receive Messages.
Hi puneet,
Thanks can you send me code for receive message
Everything is Provided in this Article : http://www.phphive.info/285/how-to-send-and-receive-messages-in-whatsapp-using-php/
Please help me how to send text php to WhatsApp please
What Problem / Error You are Facing ?
Good Morning,
Thanks for this post.
The message I’m sending are coming null in the recipient cell, I installed “protobuf” and the “curve” ….
Do you have any examples of MyEvents class.
I’m sorry for my English, I am Brazilian and I am using Gogle Translator.
Thank you very much in advance.
How do i recieve images message?
New Article on Sending & Receiving Media Messages Coming Soon !
HI!
I played a few minutes with this script and I was blocked to login again. Someone know how to unlock my number?
Once a Number is Blocked, it cant be Unblocked !
I cant receive messages 🙁 I try with this code, and another but nothing work. Do you have an idea? thnks
Provide Your PHP Code & Output !
master.zip is blank. Is there any other location?
Try Downloading Again.
you’re the best. Thank you! which is the code to send messages to whatsapp groups?
thanks for your great contribution! , greetings
No Separate Function for Sending Messages to a Group !
Just Replace WhatsApp Recipient $no with WhatsApp Group JID.
Hi,
the script is very fine, I like ist, but it´s not working fine. How does your MyEvents class Looks like and why .Do you use the $numbers array. It´s not uses in the entire script.
greetings
for me adding this line worked!!
require_once ‘Chat-API/src/events/MyEvents.php’;
I need to talk to you friend sent me your whasapp by email .
Mailed 🙂
Is there tutorial to install php-protobuf & curv21559 on web hosting?
Installing Custom PHP Extensions like PHP-Protobuf & CurvePHP on Web Hosting is Not Possible.
A Server with root Access is Required.
( VPS recommended )
Your code is works like a charm, but unable t send multiple numbers, only first event is delivering but the rest not delivering. any idea ?
Use while($wa->pollMessage()); after Every Send Event.
Hi Puneet,
I was trying to retrieve whatsapp password using this link
https://www.phphive.info/goto/aHR0cDovL3doYXRzYXBpLnBocGhpdmUuaW5mby9HZXRXaGF0c0FwcFBhc3N3b3JkLw==
But received following error.
http://prntscr.com/bjhudo
Please help to retrieve whatsapp password
GetWhatsAppPassword Tool is Moved to http://52.41.179.95/tools/GetWhatsAppPassword/
hi
i got this error.
Error: SQLSTATE[HY000] [14] unable to open database file
What do i need to do?
Thanks
Change src folder & its Files permissions to 777
Hi,
Last night I was able to send message using the complete code, but the double blue tick indicator doesn’t appear even if I replied to the messages. And this morning I can no longer send a message, and returns a Login Failed error. I know my number was block.. My question is, is there any configuration needed in MyEvents.php or in any other file to avoid blocking of the number I used? thanks in advance
Just Follow the Correct Work Flow ! Nothing Else can be Done to Prevent Block.
what so ever it will get blocked after 5 -10 messages. it seems there is no solution.
Follow the Proper Work Flow.
Login -> Sync -> Send -> Poll !
Maintain Delays between two Consecutive Messages.
You Need to Install php-sockets
Extension on Your Server
Many thanks!!!
is it possibile to send whatsapp to Group? How i can now the id of the Group?
Regards
Group Functionality Will be Added Soon !
Hi Puneet,
You’ve done a great job but I have a small issue with the line below
$token = “”; // PHPHive WhatsAPI Token, Get it from http://wapi.phphive.info
The link provided doesn’t work and I can’t get my token, is there an alternative?
Also I have one more question, do I still have to sync my contacts if I only want to send messages and not receive them?
Thanks in advance, cheers,
Hotsh0t
It is Working! Try again! No Need to Sync Contacts, our API will do it !
Buddy.. No getting blocked after few messages (8 ~ 10) in 15 mins
WhatsApp may Block Your Account!
* Maintain Proper Delays
* Send Messages only to users who have Your WhatsApp Number in their Contact List!
PHP Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[23000]: Integrity constraint violation: 19 UNIQUE constraint failed: sessions.recipient_id’ in /var/www/whatsapi/src/SqliteAxolotlStore.php:486
Install php56-pdo Extension on Your Server.
how to send pics and document through the API?
Media Sending & Receiving Support will be Added Soon !
How to send Media Messges can you please guide me
Media Sending & Receiving Support will be Added Soon !
Hey Brother,
i cant receive msg
how to fix it
can u help me
use http://wapi.phphive.info WhatsApp REST API to Send & Receive Messages.
Hi,
the links provided to get the TOKEN doesn’t work:
https://www.phphive.info/goto/aHR0cDovL3dhcGkucGhwaGl2ZS5pbmZvL2NvbnNvbGUv
http://wapi.phphive.info/console
http://wapi.phphive.info/
Thanks in advance
WhatsAPI Server is Up & Running Again 🙂
Need your contact details. Please email me.
Contact me Using https://www.phphive.info/contact/
I have got this following JSON response
while I’m trying to create a password.
{“login”:”91****710391″,”status”:”fail”,”reason”:”missing_param”,”param”:”authkey”}
Hi Thameem,
I have update the API, please try with http://chat-api.phphive.info
Documentation available at http://chat-api.phphive.info/docs
I’m getting following error:
{“error”:1,”message”:”Missing or malformed JWT”}
Hi Navraj,
PHP Snippet updated, please try again with the latest snippet.
API was working fine, next day when tired I could not scan to generate a token.
Hi Raja,
Login issue fixed, Please try again
Hello Puneet
When I try to scan the code to get a token it shows the error “couldn’t scan the code. make sure you have open web.whatsapp.com” and I already open the web.whatsapp.com.
Login issue fixed, Please try again
I get invalid hash on the login page
Login issue fixed, Please try again
hi how can I get the Jid of the Whatsapp group any tool for that
Try getting list of contacts in your device ( http://chat-api.phphive.info/docs#/device/chatsRequest )
Hi, Some times i am getting error response {“error”:1,”message”:”Login first”}. If i try 10 times then 1 time was getting success response. Most of the time, getting empty response.
Service restored, please check now
good morning, great job. it worked very well but after a few hours he wrote me: {“error”:1,”message”:”Login first”}