PHP Script to send and receive messages on
I have been reading many tutorials for sending and receiving WhatsApp Messages via PHP but there is not a single Article Which explains properly with Steps that How To retrieve Your WhatsApp password Which is created and Stored when you create a WhatsApp Account on the WhatsApp Server which is the main Challenge as of now in other Articles.
Thanks To this tool Which has Made 50% of the work Easy. https://github.com/shirioko/WART
Okay So we will Quickly go through the Steps for WhatsApp Registration Tool :
- Go To the link https://github.com/shirioko/WART
- Download The Whole project by Clicking Clone to Desktop
- Run the WART-1.7.3.0 Exe File
Enter Phone Number with Country Code (e.g. India Number : 91xxxxxxxxxx)
P.s. Do not put any Special Symbol like (+91) for India
Click on Request Code and You will Receive a Code from WhatsApp on the Entered Mobile Number.
Now Verify that Code in 2nd Step and That’s it . You are here . Your password will Appear.
P.s. Do not Share your password with Anyone Because it Can be used in loop for any Kind of messages.
okay Now we are done with 50% of the task .
Now we need to write the php Script Which will Send Messages to WhatsApp Registered Number.
You will need 2 things for Sending Messages to WhatsApp through PHP :
- Username (WHICH IS YOUR MOBILE NUMBER WITH COUNTRY CODE) : 91xxxxxxxxxxx
- Password (Which You got From The WART.EXE TOOL
Alright Sparky Lets Get this Done…..
<?php
require_once ‘./src/whatsprot.class.php’;
$username = “919xxxxxxxxx”; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = “your password”;
$w = new WhatsProt($username, 0, “Mayank Grover Blog”, true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);
$target = ’91xxxxxxxxxxx’; //Target Phone,reciever phone
$message = ‘Hello User !! This is a Tutorial for sending messages via php to WhatsApp Account’;
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
echo “Message Sent Successfully”;
?>
So Everything is Quite Clear in the above Script i.e. You need to set your Application Details Username as Mobile Number password Which you got from WART Tool Target as your Target Mobile Number and Lastly The message(Plain Text Which you need to send).
Okay Now I know many Questions are Coming in your mind.
-
In first line Require src/whatsprot.class.php What is This. ???
You Need to Download the WhatsApi from this Link . There You Will find the src
directory with all the source files.
-
Can we only Send Plain Text messages Or media like Images and Videos???
Yes we can send media file Also.
So Next I will be writing php script to send Media file To any WhatsApp Account.
If You like This Article Then please Share This.
Thank you very much for this useful article.
LikeLike
Thanks @jakkrithochoey:disqus .
LikeLike
Any WART tool for Linux?
LikeLike
@chabaleyvahernndez:disqus : Unfortunately As of now There is no WART tool for Linux
LikeLike
can the password be used to decrypt whatsapp.crypt.8 backup ?
LikeLike
Beleh : This is the password Which is Stored in WhatsApp database Corresponding to Your Mobile Number. So Whatever Unique About your Mobile Number That WhatsApp has is this password. Earlier This Password was MD5 hash of your IMEI (or MAC address), But Now It has Changed.
And as far as Decryption of Whatsapp.crypt.8 is concerned I am not sure about that may be its only One way encryption
LikeLike
i tried using this key on to decrypt the backup it didn’t work, but i’m sure there is a way to generate the key from this password
LikeLike
@beleh:disqus : I will let you know if I get to know anything about that.
Thanks.
LikeLike
i would be grateful thanks…
LikeLike
I have been Observing many Comments on Facebook that WART tool bans Your WhatsApp and all that.
So Let me tell you all WhatsApp Verifies Identity by message or by Voice call. So if you are using your Regular Mobile Number for WhatsApp Api php then It will log you out of Your WhatsApp from Mobile and will Ask you to verify Your number Again . So for One Number You can use only for one purpose either in mobile phone or In WhatsApp Api PHP . And there is nothing Like Ban on your WhatsApp Account or loss of Your Chats on WhatsApp.
So If you want to use WhatApp Api PHP Then I would Suggest To use it with an alternate Number.
Thanks.
LikeLike
Well, The WART tool doesn’t sends the Password for a already existing number! For the already existing number we have to use a Password Extractor tool, and there are scripts which already exists in the API which can be used for sending messages, videos, urls, location tec.
Source, For password : http://www.droidmen.com/2015/01/how-to-get-whatsapp-password-using-android-app/
LikeLike
is it possible to throw appropriate error notice if message delivery was unsuccessful..
btw thanks a ton for the API 🙂
LikeLike
pradeep gajanoor : In the following Script
require_once ‘./src/whatsprot.class.php’;
$username = “919xxxxxxxxx”; //Mobile Phone prefixed with country code so for india it will be 91xxxxxxxx
$password = “your password”;
$w = new WhatsProt($username, 0, “Mayank Grover Blog”, true); //Name your application by replacing “WhatsApp Messaging”
$w->connect();
$w->loginWithPassword($password);
$target = ’91xxxxxxxxxxx’; //Target Phone,reciever phone
$message = ‘Hello User !! This is a Tutorial for sending messages via php to WhatsApp Account’;
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
Now You have all the response in $w Array.
You just have to Print_r($w); and You will get all the response which you can filter according to your Use.
Thanks.
LikeLike
thanks it worked perfectly
LikeLike
i’ve implemented print_r($w) to see if the message delivered successfully but i seen hundreds of array elements don’t know which one to choose from..could you please help me with that? 🙂
thank you
LikeLike
thank you 🙂 you’re awesome 🙂
LikeLike
The code are executing successfully but i’m getting some weird output on the screen(i’ve attached a screenshot), how i’m suppose to get rid of it?
Thank you 🙂
LikeLike
screenshot..
LikeLike
Fatal error: Uncaught exception ‘Exception’ with message ‘Login Failure’ in C:wampwwwWhatsAPI-mastersrcwhatsprot.class.php:1640 Stack trace: #0 C:wampwwwWhatsAPI-mastersrcwhatsprot.class.php(474): WhatsProt->doLogin() #1 C:wampwwwwhatsapp.php(8): WhatsProt->loginWithPassword(‘hYDrWCJDwEdtlGu…’) #2 {main} thrown in C:wampwwwWhatsAPI-mastersrcwhatsprot.class.php on line 1640
LikeLike
@ernestjnrmuroiwa:disqus : Sir as per My Understanding you are running whatsapp.php file which asks you to enter the password and then it gives the error because in that file source the username and other details are hardcoded means you need to change those before use . However If you want to See this Script in Action Quickly then You can create a test.php file and paste the above code by altering it with your credentials.
Thanks.
LikeLike
@mnkgrover08 thank you for the reply
i changed credntials to the code above and it gave me that fatal error her is the code that is giving me an error
connect();
$w->loginWithPassword($password);
$target = ‘263773755300’; //Target Phone,reciever phone
$message = ‘Hello User !! This is a Tutorial for sending messages via php to WhatsApp Account’;
$w->SendPresenceSubscription($target); //Let us first send presence to user
$w->sendMessage($target,$message ); // Send Message
echo “Message Sent Successfully”;
?>
LikeLike
@ernestjnrmuroiwa:disqus : Sir in this Case please provide your Skype or Gmail Address , So that I can look Clearly into That .. Because I have tested this on my machine and its running fine.
P.s. Once try to use this on any server or public IP rather than Localhost. Thanks.
My Gmail Address is : mnkgrover08@gmail.com
LikeLike
the problem i noticed is that i tried to use my account which was concurrently active one my mobile. Used another number and it worked fine. Can not wait for the other tutorials on how to receive messages
Thank you very much
LikeLike
throwing an error
Parse error: syntax error, unexpected T_CLASS in /home/u209032999/public_html/Whatsapp/whatsapp.php on line 2
LikeLike
@bhaskarb79:disqus : Please make a seperate php file with the above code and then try. Do not try whatsapp.php file or else change the other credentials in that file source which are hardcoded.
Thanks.
LikeLike
i have made that test.php, but still it showing the same error.
LikeLike
@bhaskarb79:disqus : Are You Using Localhost ( WAMP or XAMPP) or any Public Server .
Please try with Public Server or IP.
Thanks.
LikeLike
yes firstly I tried on my xampp, and then uploaded it to my developers domain, but it’s returning error in both occasions. 😦
LikeLike
@bhaskarb79:disqus : May Be Then I need to look into your system Because i tested this on many systems its running fine. My Email is mnkgrover08@gmail.com
Send me your server Details then I will let you now.
Thanks.
LikeLike
ok done
LikeLike
Please post the solution publicly
LikeLike
@prateek_anand:disqus : Already Posted
LikeLike
Getting same error
LikeLike
@prateek_anand:disqus : I have already Posted the Solution in Above Article . However if You are not able to run this then I can help only when I can look into your code.
Thanks.
LikeLike
@Prateek on the above script please del all ‘ ‘ and ” ” and then retype again.
LikeLike
Thanks!!
LikeLike
Welcome
LikeLike
Hi Maynak, Can we use this script as a Bulk Sending. As an Example We do have a online store and We need to send promotional items via Whatsapp. Can we do it using this script ?
LikeLike
Yes 4 sure you can use this for bulk mail but if someone reports your number then your whatsapp will be blocked on that number..
So the alternative is to take around 400 – 500 numbers and rotate them and distribute the number of messages by running a cron job and also you may require to rotate your IP also
LikeLike
can please share how to switch sim number and IP.??
i was tried to switch numbers but no luck….
so please share your experience in bulk script
Thanks
LikeLike
i’ve implemented print_r($w) to see if the message delivered successfully but i seen hundreds of array elements don’t know which one to choose from..could you please help me with that? 🙂
thank you
LikeLike
Security Question: How do we know if at the of the line there is a bot (call me mitm or whatever) that stores our passwords too…
LikeLike
@andreas : yes it can be that the Wart tool which we are using for retrieving our password is storing our password and acting as a man in the middle .. And maybe the wart tool creator uses this for bulk messaging …. Anywayz that tool is present on github so they must have checked the exe for any malware Trojan or anything else… I will do a research on this using wireshark network and will suspect if any our information is going to his virtual machine
LikeLike
Thanks for the relply mnkgrover08!
😉
LikeLike
thanks you buddy.. 🙂
LikeLike
?how to run thisphp script
LikeLike
i tried using wamp server but i m failed. pls help
LikeLike
i got thiserror msg whn i tried to run it thru cmd prompt. see screenshot attached
LikeLike
@disqus_8SSkaAL8yu:disqus : please mail me your code at my email address : mnkgrover08@gmail.com
And once try to run this on live server instead of localhost.
Thanks.
LikeLike
how can i get all the incoming whatsapp messages. and store it to databases ?
LikeLike
I am receiving messages..but it is showing some xml statements when sendMessage() is called..how can i hide those xml statements.
LikeLike
Hello srimanth,
Can you please share your code to receive message from whats app? my email is saitechnobrains@gmail.com and skype id is saitechnobrains
Thanks
LikeLike
Nice Tutorial.
Thanks for sharing this with us.
Can you please guide us related to receiving whats app message and save that messages in database.
LikeLike