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 28 29 30 31 32 33 34 35 36 37 38 39
|
function admin_send_sms($destinataire, $message) {
global $connexion;
$token = 'XXXXX';
$content = $message;
if($destinataire == 'Tous'){
$numbersAll = $connexion->query("SELECT telephone FROM users WHERE telephone != NULL");
$numbers = array();
while($row = $numbersAll->fetch()){
echo $row['telephone'];
}
}else{
$numbers = array($destinataire);
}
$sender = "SENDER";
$recipients = array();
foreach ($numbers as $n) {
$recipients[] = array('value' => $n);
}
$postdata = array(
'sms' => array(
'message' => array(
'text' => $content,
'sender' => $sender
),
'recipients' => array('gsm' => $recipients)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.smsfactor.com/send");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json', 'Authorization: Bearer ' . $token));
$response = curl_exec($ch); |