The short answer: CAN NOT BE
The not-so-short answer:
You can not execute a button on an external page from PHP since all PHP codes are executed on the server side and not on the client side. The PHP code does not run in any browser, so in essence there is no link to click, even if you try to do web scraping the only thing available is the reference of the button but you will not be able to execute said button.
Of course on the server side you can run a submit event using
web scraping however the 'Send' button on the screen
whatsap is not a submit type, for that reason you could not do it
this way.
If you want to guide things on the client's side, you would need to resort to browser robotic such as Selenium .
The same I show you several solutions that I have made so you can check for yourself:
Possible solution 1: We are going to assume that you do a POST to a php server that redirects the page after loading, we will execute some script.
JS:
$.ajax({
type: 'POST',
dataType: 'json',
url: 'whatsap.php',
data: JSON.stringify({ whatsap: 'https://api.whatsapp.com/send?phone=numerodetelefonodewhatsapp&text=urldelmensaje' }),
contentType: 'application/json; charset=utf-8'
});
PHP:
<?php
$link = json_decode(file_get_contents('php://input'), true);
header('Location: '. $link['whatsap']);
exit();
?>
Solution 1 .. Failed: We can not get the page from javascript.
Possible solution 2: Web scraping
PHP: (I will use simple_html_dom for the PHP Scraping webpage):
<?php
include_once('./simple_html_dom.php');
$url = 'https://api.whatsapp.com/send?';
$data = http_build_query(array(
'phone'=>$_POST['phone'],
'text'=>$_POST['text']
));
$html = file_get_html($url.$data);
$button = $html->find('#action-button');
var_dump($button); //Aqui tienes el boton pero no puedes ejecutar el evento click.
?>
Solution 2 .. Failed: You can not run a click event using webScraping.
Possible solution 3: Paint the content of the whatsap page on your page.
PHP
<?php
$url = 'https://api.whatsapp.com/send?';
$data = http_build_query(array(
'phone'=> 'tutelefono',
'text'=> 'mensaje'
));
$html = file_get_contents($url.$data);
echo $html;
?>
Solution 3 .. Failed: You will receive the following message from the whatsap security team. : (