Skip to content

Instantly share code, notes, and snippets.

@ianjuma
Created April 29, 2016 10:43
Show Gist options
  • Save ianjuma/d85122cff6f0b2c5a9c68ac7291ced80 to your computer and use it in GitHub Desktop.
Save ianjuma/d85122cff6f0b2c5a9c68ac7291ced80 to your computer and use it in GitHub Desktop.
<?php
// Sending onDemand premium messages
require_once('AfricasTalkingGateway.php');
$username = "MyAfricasTalkingUsername";
$apikey = "MyAfricasTalkingAPIKey";
$recipient = "+254711XXXYYY";
$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
$linkId = "messageLinkId";
$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