Created
October 23, 2012 07:49
-
-
Save samwize/3937512 to your computer and use it in GitHub Desktop.
Hoiio Example: Send an SMS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Hoiio developer credentials */ | |
$hoiioAppId = "YOUR_APP_ID_HERE"; | |
$hoiioAccessToken = "YOUR_ACCESS_TOKEN_HERE"; | |
$sendSmsURL = "https://secure.hoiio.com/open/sms/send"; | |
/* Recipient of SMS */ | |
$destination = "+6511111111"; | |
$message = "Congrats! You have just sent your first SMS with Hoiio!"; | |
/* prepare HTTP POST variables */ | |
$fields = array( | |
'app_id' => urlencode($hoiioAppId), | |
'access_token' => urlencode($hoiioAccessToken), | |
'dest' => urlencode($destination), // send SMS to this phone | |
'msg' => urlencode($message) // message content in SMS | |
); | |
// form up variables in the correct format for HTTP POST | |
$fields_string = ""; | |
foreach($fields as $key => $value) | |
$fields_string .= $key . '=' . $value . '&'; | |
$fields_string = rtrim($fields_string,'&'); | |
/* initialize cURL */ | |
$ch = curl_init(); | |
/* set options for cURL */ | |
curl_setopt($ch, CURLOPT_URL, $sendSmsURL); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); | |
/* execute HTTP POST request */ | |
$result = curl_exec($ch); | |
print($result); | |
/* close connection */ | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment