Page 1 of 1
How to send WhatsApp messages to phones using PHP
Posted: 2020-05-25 15:30
by jsetzer
Hi AppGineers,
can anyone of you tell, how to
send text notifications to WhatsApp phone numbers
using PHP?

- chrome_afCi9P5qnn.png (2.66 KiB) Viewed 24459 times
I'd like to notify users about certain tasks or status changes. I can store their phone numbers in AppGini and [x] check if they want to be informed or not. It is just about notification; there is no need for processing any responses.
I have read there is no WhatsApp API any longer and it seems we need to contract with an official gateway provider like TWILIO. Can anyone please share her/his experiences.
Thanks in advance!
Regards,
Jan
Re: How to send WhatsApp messages to phones using PHP
Posted: 2020-05-25 16:13
by G Belgrado
Hi Jan
there would be this for whatsapp API
API WhatsApp Business
but it's not free
Re: How to send WhatsApp messages to phones using PHP
Posted: 2020-05-26 04:46
by D Oliveira
Hey Jan, I have something that could help you, mobile version will use native whatsapp and desktop version will use whatsapp web, hope it helps =)
Code: Select all
<div>
<button onclick="share();" style="background-color:rgba(0,0,0,0.4);border-top-left-radius: 5px;border-bottom-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;color:white;font-size:20px;font-family:Gotham2;border:0.1px solid black;padding: 5px 10px 7px;">
Share via Whatsapp </button>
</div>
<div>
<img src="spacer.png?c=91" style="width:100%;height:50px;">
</div>
<?php
function isMobile() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
if(isMobile()){
?>
<script>
function share(){
LinkTextToShare = 'https://api.whatsapp.com/send?text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
//setInterval(function(){ popup_window.close (); }, 1000);
popup_window.close ();
}
</script>
<?php }else{
?>
<script>
function share(){
LinkTextToShare = 'https://web.whatsapp.com/send?l=en&text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
}
</script>
<?php }
?>
<img src="spacer.png?c=91" style="width:100%;height:30px;">
Re: How to send WhatsApp messages to phones using PHP
Posted: 2020-05-26 04:51
by jsetzer
Hi,
did you manage to use it according to the docs?
I have already seen that documentation page before. They are talking about a registration, but there is not even a "login" or "register" link on the page they are refering to.
Thanks anyway!
Jan
Re: How to send WhatsApp messages to phones using PHP
Posted: 2020-05-26 04:58
by jsetzer
D Oliveira wrote: ↑2020-05-26 04:46
Hey Jan, I have something that could help you, mobile version will use native whatsapp and desktop version will use whatsapp web, hope it helps =)
Code: Select all
<div>
<button onclick="share();" style="background-color:rgba(0,0,0,0.4);border-top-left-radius: 5px;border-bottom-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;color:white;font-size:20px;font-family:Gotham2;border:0.1px solid black;padding: 5px 10px 7px;">
Share via Whatsapp </button>
</div>
<div>
<img src="spacer.png?c=91" style="width:100%;height:50px;">
</div>
<?php
function isMobile() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
if(isMobile()){
?>
<script>
function share(){
LinkTextToShare = 'https://api.whatsapp.com/send?text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
//setInterval(function(){ popup_window.close (); }, 1000);
popup_window.close ();
}
</script>
<?php }else{
?>
<script>
function share(){
LinkTextToShare = 'https://web.whatsapp.com/send?l=en&text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
}
</script>
<?php }
?>
<img src="spacer.png?c=91" style="width:100%;height:30px;">
Hi,
thank you. Unfortunately this is clientside Javascript which requires a WhatsApp installation or an open WhatsAppWeb-session + additional user interaction.
I am looking for a server side PHP solution which I can use for mass sending WhatsApp messages to known phone numbers without user interaction per message.
Thank you both for taking the time!
Regards,
Jan
Re: How to send WhatsApp messages to phones using PHP
Posted: 2020-05-26 22:25
by D Oliveira
jsetzer wrote: ↑2020-05-26 04:58
D Oliveira wrote: ↑2020-05-26 04:46
Hey Jan, I have something that could help you, mobile version will use native whatsapp and desktop version will use whatsapp web, hope it helps =)
Code: Select all
<div>
<button onclick="share();" style="background-color:rgba(0,0,0,0.4);border-top-left-radius: 5px;border-bottom-left-radius: 5px;border-top-right-radius: 5px;border-bottom-right-radius: 5px;color:white;font-size:20px;font-family:Gotham2;border:0.1px solid black;padding: 5px 10px 7px;">
Share via Whatsapp </button>
</div>
<div>
<img src="spacer.png?c=91" style="width:100%;height:50px;">
</div>
<?php
function isMobile() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
if(isMobile()){
?>
<script>
function share(){
LinkTextToShare = 'https://api.whatsapp.com/send?text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
//setInterval(function(){ popup_window.close (); }, 1000);
popup_window.close ();
}
</script>
<?php }else{
?>
<script>
function share(){
LinkTextToShare = 'https://web.whatsapp.com/send?l=en&text=' + encodeURIComponent(window.location.href) ;
popup_window = window.open(LinkTextToShare,"_blank");
}
</script>
<?php }
?>
<img src="spacer.png?c=91" style="width:100%;height:30px;">
Hi,
thank you. Unfortunately this is clientside Javascript which requires a WhatsApp installation or an open WhatsAppWeb-session + additional user interaction.
I am looking for a server side PHP solution which I can use for mass sending WhatsApp messages to known phone numbers without user interaction per message.
Thank you both for taking the time!
Regards,
Jan
sorry for the confusion, maybe those links can help:
https://www.phphive.info/285/how-to-sen ... using-php/
https://www.twilio.com/docs/whatsapp/tu ... atsapp-php
http://www.vetbossel.in/send-and-receiv ... using-php/
Cheers!
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 11:00
by a.gneady
I know this is an old thread, but I just posted a related recipe to the
AppGini customization cookbook on GitHub:
Share a record as a WhatsApp message
This is a client-side solution that opens the WhatsApp-web page, with a preselected contact and a pre-written message, ready for the user to click send. For sending automated server-side WhatsApp messages, I guess the only official way is to use the WhatsApp API -- I believe it's a commercial API rather than free.
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 12:07
by jsetzer
Great, this works perfectly for clientside 1:1 communication if the sender has connected her/his smartphone to WhatsApp Web. Thanks for sharing!
Serverside (API) usage: I did not find any free alternative, yet.
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 12:19
by jsetzer
Tips for text-formatting
- *bold*
- _italic_
- ~strike~
- ```monospace```
- you can use `\n` as newline-character

- chrome_lwlw5D1lY8.png (4.14 KiB) Viewed 22711 times

- chrome_gJ2b5mTZjD.png (11.71 KiB) Viewed 22711 times

- chrome_VnHwO9pv2n.png (4.18 KiB) Viewed 22711 times
Question:
Does anyone know the meaning of app_absent=0 parameter? Is there a parameter documentation somewhere?
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 12:52
by onoehring
Hi Jan,
just from curiosity: Why not simply send an email? That mail can be as short as a regular whatsapp message.
(Well, it's always good if we can - I agree)
Just a note from someone who might just be the only one here not using whatsapp
Olaf
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 12:52
by onoehring
Hi,
forgot, maybe, depending on usergroup you could use an instant messenger, based on email:
https://delta.chat/
Olaf
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 13:13
by jsetzer
@Olaf: In my case (see beginning of this thread) a customer of mine had dozens of workers on construction sites. They are used to receive all organizational information in there specific WhatsApp team-group. So for that use case it is not an option to completely change their usual information-flow. Thanks for the link. I will definately have a look at this.
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-04 13:28
by jsetzer
By the way:
Thanks to Ahmed's WhatsApp recipe (see above) I have just included a WhatsApp link in one of my login pages (just as an idea).

- chrome_5uYBgEPaih.png (116.2 KiB) Viewed 22699 times
It allows users to send the URL of that specific website via WhatsApp to others or to themselves. It is a little bit faster and more conveniant than copy&paste.
Other elements inside the "Connect" box:
- The "paperplane" button opens up your mail client and creates a new mail, already containing the URL as link. So you can send the URL by email with very few clicks.
- The QR code can be scanned with your smartphone (if it has QR Code scanner integrated or as an installed app) and directly opens the same page.
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-06 11:46
by jsetzer
@Olaf:
Once again thank you for sharing the
DeltaChat tip for automated sending messages to Smartphones which have installed
DeltaChat client.
Unfortunately, I did not get it running, yet, and I would appreciate your help and experiences.
Status quo
- As you have suggested, I have installed DeltaChat on my PC and on my Smartphone
- I have setup a blank new email account just for testing purposes
- I have connected both clients (Desktop + Smartphone) with that email account
That's fine: I can use those DeltaChat clients on different devices for sending and receiving messages.
Problem
I did not manage to send an e-mail (for example using PHP or by a standard e-mail client) to a DeltaChat client (Desktop or smartphone).
Analysis
When watching the email inbox while sending a message using one of the DeltaChat clients I have seen that DeltaChat uses attachments for data-transfer. They are using PGP (pretty good privacy).
As you can see from the following screenshot, such a message does NOT contain any contents but two attachments:

- chrome_cmxdRb6uIQ.png (15.02 KiB) Viewed 22610 times
The .asc file contains PGP-encrypted data.
The .pgp file just contains three lines (two of them are empty):

- Code_xsgSrR55HC.png (1.09 KiB) Viewed 22610 times
Right now I have no idea how to encrypt my plain-text or HTML-messages using a PGP key of a recipient
if I only have the recipient's email address.
So my question is:
How can I send a message to a DeltaChat client without using a DeltaChat client itself?
Thanks again for your recommendation and support!
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-08 10:01
by onoehring
Hi Jan,
oh well, I did not try this before myself, maybe I am not of a big help here but. I thought as DeltaChat is essentially using email it should be able to receive standard mail....
Looking at the headers I find
Maybe you need to send the headers along, so that DeltaChat recognizes, that the mail is intended for it. For the second line see specifications here:
https://autocrypt.org/examples.html .
Hope this helps .. a little.
Olaf
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-08 10:05
by onoehring
Hi Jan,
maybe write yourself a message from DeltaChat (to your regular email account) and look at this message. Can you reply to that and receive it on DeltaChat? If yes, you should probably be able to take the message apart and send directly (without anyone initiating the "chat" first).
Just a thought.
Olaf
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-08 15:44
by eagle
Just wanted to chime in with this related tip.
Would it be possible to convince the customer to use Telegram instead of (or in addition to WhatsApp)? Telegram has a super, free, API that makes it very easy to send messages from PHP. At work we use it to monitor server uptime, mail queues etc and I get a Telegram message whenever anything needs attention. We also have connected it to our CRM system to "ring the bell" whenever new sales contracts are closed.
Eagle.
Re: How to send WhatsApp messages to phones using PHP
Posted: 2021-02-08 19:18
by jsetzer
Thank you for your idea with Telegram API. I will keep it in mind for future projects. In this specific project, we will not be able to completely convert their staff to the use of telegram. WhatsApp has been used there for years in various process-steps, and as a manufacturer of a partial solution I cannot change the process information flow.
Anyway, thanks for the idea. I think it is very valuable that you have already gained experience with this.