Skip to content

Instantly share code, notes, and snippets.

@dv336699
Forked from lesiki/fsmswebconnection.php
Created May 20, 2015 15:51
Show Gist options
  • Save dv336699/5c7f1633d0f547d94ba4 to your computer and use it in GitHub Desktop.
Save dv336699/5c7f1633d0f547d94ba4 to your computer and use it in GitHub Desktop.
<?php //FILE: sms_api.php
function sendSMS($number,$message,$concat = 1) {
$url = "example"; // Set your frontlinesms or frontlinecloud webconnection url here
$secret = "secret"; // Set the secret here
$request = array(
'secret' => $secret,
'message' => $message,
'recipients' => array(array(
'type' => 'address',
'value' => $number
))
);
$req = json_encode($request);
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $req );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
return explode(',',$result);
}
?>
<?php //FILE: index.php
include 'sms_api.php';
$number = '+123456789';
$text = 'Hi There, how are you?';
$sms_api_result = sendSMS($number, $text);
// Check if SMS was sent
if ($sms_api_result[0] == 'OK') {
// Ok, SMS received by the API
echo 'The SMS was sent.';
}
else {
// Failure, SMS was not sent
// In this example we display the response to identify the error
print_r($sms_api_result);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment