Skip to content

Instantly share code, notes, and snippets.

@jokamjohn
Created October 19, 2015 10:34
Show Gist options
  • Select an option

  • Save jokamjohn/af210360f8e183e75477 to your computer and use it in GitHub Desktop.

Select an option

Save jokamjohn/af210360f8e183e75477 to your computer and use it in GitHub Desktop.
<?php
require_once(‘AfricasTalkingGateway.php’);
//next we receive notification from API
//and read in post params to our variables
$apiUsername =config('sms.username');
$apikey =config('sms.api_key');
if($_POST)
{
$number = $POST_['phoneNumber'];
$shortcode = $_POST['shortCode'];
$keyword = $_POST['keyword'];
$updateType = $POST_['updateType'];
/*
$number = ‘+254721748323′;
$shortcode = ’22384′;
$text = ‘love‘;
$updateType = ‘Addition’;
*/
if($updateType==’Addition’)
{
//Create a SQL query
//persist in db
//invoke sendMessage and try to send
$recipients = $number;
$message = 'You are my love';
$gateway = new AfricasTalkingGateway($apiUsername, $apikey);
try
{
$from = '22384';
$bulkSmsMode = '0';
$params = array();
$params['keyword'] = 'Love';
// Thats it, hit send and we’ll take care of the rest.
$results = $gateway->sendMessage($recipients, $message,$from,$bulkSmsMode,$params);
foreach($results as $result)
{
$messageId = $result->messageId;
$status = $result->status;
//persist in outbox
}
}
catch ( AfricasTalkingGatewayException $e )
{
//echo “Encountered an error while sending: “.$e->getMessage();
echo "Encountered an error while sending: ".$e->getMessage();
}
#################################
//exit
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment