Skip to content

Instantly share code, notes, and snippets.

@JaniKibichi
Created March 21, 2017 08:38
Show Gist options
  • Save JaniKibichi/0c922ac691e6b9ad26bce1dfeeff589d to your computer and use it in GitHub Desktop.
Save JaniKibichi/0c922ac691e6b9ad26bce1dfeeff589d to your computer and use it in GitHub Desktop.
SMS On-demand Script - AT
<?php
//Receive POST from AT
$Sender = $_POST['from'];
$to = $_POST['to'];
$text = $_POST['text'];
$date = $_POST['date'];
$id = $_POST['id'];
$linkId = $_POST['linkId']; //This works for onDemand subscription products
if(!empty($_POST['from'])){
// Sending onDemand premium messages
require_once('AfricasTalkingGateway.php');
$username = "MyAfricasTalkingUsername";
$apikey = "MyAfricasTalkingAPIKey";
$recipient = $Sender;
$shortCode = "XXXXX";
$keyword = "premiumKeyword"; // $keyword = null;
$bulkSMSMode = 0;
// Create an array which would hold parameters keyword, retryDurationInHours and linkId
// linkId is received from the message sent by subscriber to your onDemand service
$options = array('keyword'=> $keyword, 'linkId'=> $linkId,'retryDurationInHours' => "No of hours to retry");
$message = "Get your daily message and thats how we roll.";
$gateway = new AfricasTalkingGateway($username, $apikey);
try
{
$results = $gateway->sendMessage($recipient, $message, $shortCode, $bulkSMSMode, $options);
foreach($results as $result) {
echo " Number: " .$result->number;
echo " Status: " .$result->status;
echo " MessageId: " .$result->messageId . "\n";
}
}
catch ( AfricasTalkingGatewayException $e ){ echo "Encountered an error while sending: ".$e->getMessage(); }
// DONE!!!
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment