<?php
if(!isset($_POST['message'])){
  exit();
}
include 'iconnect.php';
$contact_group=filter_var($_POST['group'],FILTER_SANITIZE_STRING);
$textMessage=filter_var($_POST['message'],FILTER_SANITIZE_STRING);
$text_recipients=contact_recipients($contact_group);
sendTextMessage($textMessage,$text_recipients);
function sendTextMessage($message,$recipients){
  require_once('AfricasTalkingGateway.php');
  $username   = "nessinfortech";
  $apikey     = "dc013d9e2725ed67257387c35f61d209c775482b93aab364e9dddd18a1431a30";
  //$recipients = "+254712993080,+254725359768";
  //$recipients="+254712993080,+254725359768,+254704544611,+254724944042";
  //$message    = "THANK YOU FOR SUPPORTING AGNES NJAMBI GITHINJI FOR NAKURU WOMEN REP #NJAMBI";
  // Specify your AfricasTalking shortCode or sender id
//  echo $message;
//  echo $recipients;
  //exit();
  $from = "shortCode or senderId";
  $gateway    = new AfricasTalkingGateway($username, $apikey);
  try
  {

     $results = $gateway->sendMessage($recipients, $message);

    foreach($results as $result) {
      /*echo " Number: " .$result->number;
      echo " Status: " .$result->status;
      echo " MessageId: " .$result->messageId;
      echo " Cost: "   .$result->cost."\n"; */
    }
  }
  catch ( AfricasTalkingGatewayException $e )
  {
    echo "Encountered an error while sending: ".$e->getMessage();
  }
  // DONE!!!
}
//Sending Messages using sender id/short code
