PHP: usare le API di Clickatell per inviare SMS

In PHP possiamo inviare SMS con le API di Clickatell.

PHP di Gabriele Romanato

In PHP possiamo inviare SMS con le API di Clickatell.

La soluzione è la seguente:


function my_send_sms($recipient = '390001234567', $message = 'Hello World') {
    $to = "[\"$recipient\"]";
    $authToken = "Auth Token";
        
    $ch = curl_init();
        
    curl_setopt($ch, CURLOPT_URL,            "https://api.clickatell.com/rest/message");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST,           1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,     "{\"text\":\"$message\",\"to\":$to}");
    curl_setopt($ch, CURLOPT_HTTPHEADER,     [
        "X-Version: 1",
        "Content-Type: application/json",
        "Accept: application/json",
        "Authorization: Bearer $authToken"
    ]);
        
    $result = curl_exec($ch);
    curl_close($ch);
}