Last active
August 29, 2015 14:10
-
-
Save dljoseph/d969101e67a90bd659d6 to your computer and use it in GitHub Desktop.
Send an SMS with PHP via TXTNation API
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 | |
//error_reporting(E_ALL); | |
//ini_set( 'display_errors','1'); | |
$strPostUrl = 'http://client.txtnation.com/mbill.php'; | |
$strPostReq = ''; | |
//now send SMS | |
//Set your ekey | |
$ekey = 'PUT YOUR TXTNATION KEY HERE'; | |
//Set the amount to charge | |
$value ='0.00'; | |
//Set the currency to charge | |
$currency ='gbp'; | |
$strNumber = $mobile; | |
$strMessage = "#COMPETITIONWINNER - You've won a FREE <PRIZE NAME HERE>. Take this code in store to collect: $voucher_code. Code valid only for today. Terms apply, see bit.ly/xyzabc"; | |
$strNetwork = 'INTERNATIONAL'; | |
$intId = time(); | |
//Insert your DB save details here and generate return post string | |
$strPostUrl = 'http://client.txtnation.com/mbill.php'; | |
$strPostReq .= 'reply=0'; | |
$strPostReq .= '&id='.$intId; | |
$strPostReq .= '&number='.$strNumber; | |
$strPostReq .= '&network='.$strNetwork; | |
$strPostReq .= '&message='.$strMessage; | |
$strPostReq .= '&value='.$value; | |
$strPostReq .= '¤cy='.$currency; | |
$strPostReq .= '&cc=bd'; | |
$strPostReq .= '&title=ATTENTION'; | |
$strPostReq .= '&ekey='.$ekey; | |
//return post to txtNation server | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_URL,$strPostUrl); | |
curl_setopt($ch,CURLOPT_POST,1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS,"$strPostReq"); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$strBuffer = curl_exec($ch); | |
curl_close($ch); | |
//Check to see if the post is a success | |
if(strstr($strBuffer,'SUCCESS')){ | |
//Output OK to confirm you have processed the transaction | |
echo "OK"; | |
} else{ | |
//Capture Error | |
echo $strBuffer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment