
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

function send_sms_api ($to,$message){

$to="966".ltrim($to,"0");

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://api.taqnyat.sa/v1/messages");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'
{
"recipients": ['.$to.'],
"body":"'.$message.'",
"sender":"Taajeer"
}
');

 /* set the content type json */
    $headers = [];
    $headers[] = 'Content-Type:application/json';
    $token = "a69f83df3e490a170905974ed3dcc9eb";
    $headers[] = "Authorization: Bearer ".$token;
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

// In real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

print_r($server_output);

curl_close($ch);

// Further processing ...
//if ($server_output == "OK") { ... } else { ... }
}


send_sms_api("0565845759","Testing PHP Script");



?>