CellTrust Secure SMS Gateway API (HTTPS) - Sample Code
You can use HTTPS protocol to connect to the CellTrust SMS Gateway. It supports two way messaging and connects to any application, including static websites with HTML pages. Only one line of HTML code is required to send messages once you register and obtain a username. To receive messages, the CellTrust SMS Gateway will perform a FORM-POST with message content to your web servers.
//your username and nickname are GENERALLY the same, when in doubt, try username for both fields
$USERNAME = "YOURUSERNAME";
$PASSWORD = "YOURPASSWORD";
$NICKNAME = "YOURNICKNAME";
//PHONE DESTINATION/NUMBER TO SEND MESSAGE TO (BE SURE TO INCLUDE COUNTRYCODE)
$SMSDESTINATION ="14805551212";
//SPECIFIES WHETHER MESSAGE CAN BE DELIVERED EVEN IF NO AGENT INSTALLED
$ALLOWINSECURE = "TRUE";
//SPECIFIES WE WANT TO RECEIVE READ AND DELIVERY ACK’S FROM AGENT
$READACK = "TRUE";
//URL TO POST TO FOR API – PLEASE DON’T EDIT
$URL = "https://www.primemessage.net/TxTNotify/SecureSMS?";
//PARAMETERS TO BE POSTED TO URL USED IN API
$DATA = "Username=".$USERNAME."&Password=".$PASSWORD."&Nickname="
.$NICKNAME."&SMSDestination=".$SMSDESTINATION.
"&Message="Test+message"."&AllowInsecure=".$ALLOWINSECURE;
//CALL FUNCTION, AND PRINT OUT SERVERS RESPONSE
echo do_post_request($URL, $DATA);
//should work in PHP 4 and 5
function do_post_request($url, $data, $optional_headers = null) {
$start = strpos($url,'//')+2;
$end = strpos($url,'/',$start);
$host = substr($url, $start, $end-$start);
$domain = substr($url,$end);
$fp = pfsockopen($host, 80);
if(!$fp) return null;
fputs ($fp,"POST $domain HTTP/1.1\n");
fputs ($fp,"Host: $host\n");
if ($optional_headers) {
fputs($fp, $optional_headers);
}
fputs ($fp,"Content-type: application/x-www-form-urlencoded\n");
fputs ($fp,"Content-length: ".strlen($data)."\n\n");
fputs ($fp,"$data\n\n");
$response = "";
while(!feof($fp)) {
$response .= fgets($fp, 1024);
}
fclose ($fp);
return $response;
}
?>
Sending message via HTTPS - GET (from your servers to mobile devices), PHP sample code
//your username and nickname are GENERALLY the same, when in doubt, try username for both fields
$USERNAME = "YOURUSERNAME";
$PASSWORD = "YOURPASSWORD";
$NICKNAME = "YOURNICKNAME";
//PHONE DESTINATION/NUMBER TO SEND MESSAGE TO (BE SURE TO INCLUDE COUNTRYCODE)
$SMSDESTINATION ="14805551212";
//SPECIFIES WHETHER MESSAGE CAN BE DELIVERED EVEN IF NO AGENT INSTALLED
$ALLOWINSECURE = "TRUE";
//SPECIFIES WE WANT TO RECEIVE READ AND DELIVERY ACK’S FROM AGENT
$READACK = "TRUE";
//URL TO POST TO FOR API – PLEASE DON’T EDIT
$URL = "https://www.primemessage.net/TxTNotify/SecureSMS?";
//PARAMETERS TO BE POSTED TO URL USED IN API
$DATA = "Username=".$USERNAME."&Password=".$PASSWORD."&Nickname="
.$NICKNAME."&SMSDestination=".$SMSDESTINATION.
"&Message="Test+message"."&AllowInsecure=".$ALLOWINSECURE;
//CALL FUNCTION, AND PRINT OUT SERVERS RESPONSE
echo do_post_request($URL, $DATA);
//should work in PHP 4 and 5
function do_post_request($url, $data, $optional_headers = null) {
$start = strpos($url,'//')+2;
$end = strpos($url,'/',$start);
$host = substr($url, $start, $end-$start);
$domain = substr($url,$end);
$fp = pfsockopen($host, 80);
if(!$fp) return null;
fputs ($fp,"POST $domain HTTP/1.1\n");
fputs ($fp,"Host: $host\n");
if ($optional_headers) {
fputs($fp, $optional_headers);
}
fputs ($fp,"Content-type: application/x-www-form-urlencoded\n");
fputs ($fp,"Content-length: ".strlen($data)."\n\n");
fputs ($fp,"$data\n\n");
$response = "";
while(!feof($fp)) {
$response .= fgets($fp, 1024);
}
fclose ($fp);
return $response;
}
?>
