function __construct() { require_once 'topfile.php'; if (isset($_REQUEST['gmidentity']) && isset($_REQUEST['gmmessage'])) { #sanitization $this->gmidentity = $db->real_escape_string($_REQUEST['gmidentity']); $this->gmmessage = $db->real_escape_string($_REQUEST['gmmessage']); #check empty if (!empty($this->gmidentity) && !empty($this->gmmessage)) { if ($group_msg == 1) { # GET PHONE NUMBERS AND GROUP DATA $gd = $db->query("SELECT * FROM `sms_group_members` WHERE `group`='{$this->gmidentity}'"); while ($userdata = $gd->fetch_array()) { $user_id = $userdata['member']; # get phone number $user_tbl_check = $db->query("SELECT * FROM `sms_contacts` WHERE `id`='{$user_id}'"); $data_nos = $user_tbl_check->fetch_array(); $listNos .= $data_nos['phone_number'] . ","; } $grd = $db->query("SELECT * FROM `sms_groups` WHERE `id`='{$this->gmidentity}'"); $group_data = $grd->fetch_array(); $groupName = $group_data['group_name']; # SMS Code $username = $as_username; $apikey = $as_key; if ($as_sender_id == "") { $from = "SMSLEOPARD"; } else { $from = $as_sender_id; } $recipients = $listNos; $message = $this->gmmessage; $gateway = new AfricasTalkingGateway($username, $apikey); try { $results = $gateway->sendMessage($recipients, $message, $from); if ($results) { $date = date('d-M-Y H:i:s'); //save record $saveRecord = $db->query("INSERT INTO `sms_logs`(`sent_to`,`message`,`date`,`by`)\n\t\t\t\t\t\t\t\t\t VALUES('{$groupName}','{$this->gmmessage}','{$date}','{$_SESSION['bulkadmin']}')"); if ($mybalance < $setminimum) { $savemin = $db->query("INSERT INTO `sms_activity`(`activity_log`)\n\t\t\t\t\t\t\t\t\t VALUES('lowcredit')"); } } if ($saveRecord) { echo '<p style="color:green"><i class="fa fa-check-square"></i> Message sent</p>'; } } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while sending: " . $e->getMessage(); } } else { echo '<p style="color:orange"><i class="fa fa-lock"></i> Sorry, you do not have permissions to send open messages</p>'; } } else { echo '<p style="color:orange">Please provide phone number and message</p>'; } } }
function __construct() { require_once 'topfile.php'; if (isset($_REQUEST['inlineno']) && isset($_REQUEST['inlinemsg'])) { #sanitization $this->inlineno = $db->real_escape_string($_REQUEST['inlineno']); $this->inlinemsg = $db->real_escape_string($_REQUEST['inlinemsg']); #check empty if (!empty($this->inlineno) && !empty($this->inlinemsg)) { if ($open_msg == 1) { if (strpos($this->inlineno, '+') !== false) { # SMS Code $username = $as_username; $apikey = $as_key; if ($as_sender_id == "") { $from = "SMSLEOPARD"; } else { $from = $as_sender_id; } $recipients = $this->inlineno; $message = $this->inlinemsg; $gateway = new AfricasTalkingGateway($username, $apikey); try { $results = $gateway->sendMessage($recipients, $message, $from); if ($results) { $date = date('d-M-Y H:i:s'); //save record $saveRecord = $db->query("INSERT INTO `sms_logs`(`sent_to`,`message`,`date`,`by`)\n\t\t\t\t\t\t\t\t\t VALUES('{$recipients}','{$message}','{$date}','{$_SESSION['bulkadmin']}')"); if ($mybalance < $setminimum) { $savemin = $db->query("INSERT INTO `sms_activity`(`activity_log`)\n\t\t\t\t\t\t\t\t\t VALUES('lowcredit')"); } } if ($saveRecord) { echo '<p style="color:green"><i class="fa fa-check-square"></i> Message sent</p>'; } } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while sending: " . $e->getMessage(); } } else { echo '<p style="color:orange">Phone number should be in full international format (+25478*****)</p>'; } } else { echo '<p style="color:orange"><i class="fa fa-lock"></i> Sorry, you do not have permissions to send open messages</p>'; } } else { echo '<p style="color:orange">Please provide phone number and message</p>'; } } }
public function sendSMSFromArray($to, $message) { // Be sure to include the file you've just downloaded $recipients = array(); foreach ($to as $key => $value) { $to = substr($value, -9); $to_end = '+254' . $to; array_push($recipients, $to_end); } if (count($recipients) > 0) { $recpts = implode(',', $recipients); // require_once('../libraries/AfricasTalkingGateway.php'); // Specify your login credentials $username = "******"; $apikey = "abbfa09e621a6ece272a254e3fcd910657ff46e88f82db205499603d06dda908"; // Specify the numbers that you want to send to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) $recipients = '+254' . $to; //can be comma separeted $from = '20151'; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recpts, $message, $from); if ($results) { return $results; } else { return 0; } // foreach($results as $result) { // // Note that only the Status "Success" means the message was sent // 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(); } } else { return 0; } // DONE!!! }
/** The gateway will return 100 subscription numbers at a time back to you, starting with * what you currently believe is the lastReceivedId. Specify 0 for the first * time you access the gateway, and the ID of the last message we sent you * on subsequent results * * @return string */ public function subscriptions() { \Log::debug('begin fetch'); try { $lastReceivedId = 0; \Log::debug('start fetch'); do { $results = $this->gateway->fetchPremiumSubscriptions($this->shortCode, $this->keyword, $lastReceivedId); foreach ($results as $result) { echo "\n"; $lastReceivedId = $result->id; $message = " From: " . $result->phoneNumber . " id: " . $result->id; \Log::debug('message fetch'); return $message; } // return $results; } while (count($results) > 0); \Log::debug('done fetch'); //TODO Be sure to save lastReceivedId here for next time. } catch (AfricasTalkingGatewayException $e) { return "Encountered an error: " . $e->getMessage(); } }
public function sendSms($recipients, $message) { $gateway = new AfricasTalkingGateway($this->username, $this->apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recipients, $message); foreach ($results as $result) { $newSend = new SentMessages(); $newSend->number = $result->number; $newSend->message_id = $result->messageId; $newSend->status = $result->status; $newSend->save(); // Note that only the Status "Success" means the message was sent 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(); } }
function sendAirtime($recipients) { require_once "AfricasTalkingGateway.php"; //Specify your credentials $username = "******"; $apiKey = "apikey"; $recipientStringFormat = json_encode($recipients); //Create an instance of our awesome gateway class and pass your credentials $gateway = new AfricasTalkingGateway($username, $apiKey); try { $results = $gateway->sendAirtime($recipientStringFormat); foreach ($results as $result) { echo $result->status; echo $result->amount; echo $result->phoneNumber; echo $result->discount; echo $result->requestId; //Error message is important when the status is not Success echo $result->errorMessage; } } catch (AfricasTalkingGatewayException $e) { echo $e->getMessage(); } }
public function sendSMS($phone_number, $output, $shortcode = 20151, $sms_gateway_id = null) { // echo "hapa"; // exit; //$phone_number = "+254728355429"; //invalidating stuff //$phone_number = "+254728355429dfsdg"; $shortcode = 20151; if ($shortcode > 1) { $username = "******"; $apiKey = "abbfa09e621a6ece272a254e3fcd910657ff46e88f82db205499603d06dda908"; $gateway = new AfricasTalkingGateway($username, $apiKey); //print_r(is_array($output)); //exit; if (is_array($output)) { //print_r($output); //exit; foreach ($output as $key => $value) { //print_r($shortcode); //exit; $value = $value; try { // Send a response originating from the short code that received the message $results = $gateway->sendMessage($phone_number, $value, $shortcode); //$results = $gateway -> sendMessage("+254728355429", $value, $shortcode); // Read in the gateway response and persist if necessary $response = $results[0]; $status = $response->status; $cost = $response->cost; //print_r($value); //print_r($status); //exit; } catch (AfricasTalkingGatewayException $e) { // Log the error $errorMessage = $e->getMessage(); //print_r($errorMessage); //exit; } //print_r($value); //exit; } //exit; } else { try { //Send a response originating from the short code that received the message //$results = $gateway -> sendMessage('+254728355429', $output, $shortcode); $output = $output; //print_r($append); //exit; $results = $gateway->sendMessage($phone_number, $output, $shortcode); // Read in the gateway response and persist if necessary $response = $results[0]; $status = $response->status; $cost = $response->cost; //print_r($output); //print_r($status); //exit ; } catch (AfricasTalkingGatewayException $e) { // Log the error $errorMessage = $e->getMessage(); } } } elseif ($sms_gateway_id = 3) { //telerivet magic over here //require_once ('AfricasTalkingGateway.php'); header("Content-Type: application/json"); echo json_encode(array('messages' => array(array('content' => $output)))); //echo "tel".$output; exit; } else { //$output = json_decode($output); if (is_array($output)) { foreach ($output as $key => $value) { print_r("array " . $value); exit; } } else { //echo "hapa"; //print_r($output); //exit ; } } //exit; }
function __construct() { if (isset($_REQUEST['loginusername']) && isset($_REQUEST['loginpassword'])) { require_once 'config.php'; #sanitization $this->dbo_ = $db; $this->username = $this->dbo_->real_escape_string($_REQUEST['loginusername']); $this->password = $this->dbo_->real_escape_string($_REQUEST['loginpassword']); #check empty if (!empty($this->username) && !empty($this->password)) { #convert password $passhash = md5($this->password); #check against database for record $login = $this->dbo_->query("SELECT * from `sms_users` WHERE `username`='{$this->username}' && `password`='{$passhash}'"); if ($login->num_rows > 0) { # get some user data $userdata = $login->fetch_array(); $userphone = $userdata['phone']; # check login pass type $passtype = "SELECT * FROM `sms_settings`"; if ($passtype_run = $this->dbo_->query($passtype)) { $passtype_data = $passtype_run->fetch_array(); # fetch needed data, in our case 2 factor login,as_username,as_pass and as_sender $allow2factor = $passtype_data['security_2_factor']; $as_username = $passtype_data['as_username']; $as_key = $passtype_data['as_key']; $as_sender_id = $passtype_data['as_sender_id']; if ($allow2factor == 2) { # Generate two factor code $remote_access_code = rand(1000, 9999); $this->dbo_->query("UPDATE `sms_users` SET `login_pass`='{$remote_access_code}' WHERE `username`='{$this->username}'"); # SMS Code $username = $as_username; $apikey = $as_key; if ($as_sender_id == "") { $from = "SMSLEOPARD"; } else { $from = $as_sender_id; } $recipients = $userphone; $message = "Your login code is " . $remote_access_code; $gateway = new AfricasTalkingGateway($username, $apikey); try { $results = $gateway->sendMessage($recipients, $message, $from); if ($results) { $_SESSION['sandbox'] = $this->username; echo $this->json_encoder("runsteptwo"); } } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while sending: " . $e->getMessage(); } } else { $_SESSION['bulkadmin'] = $this->username; echo $this->json_encoder("successlogin"); } } else { echo '<p style="color:orange;"> Something went wrong</p>'; } } else { echo '<p style="color:orange;"> Wrong Username or Password</p>'; } } else { echo '<p style="color:orange;">Please fill all fields</p>'; } } }
<?php // Be sure to include our gateway class require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "MyAfricasTalking_APIKey"; // Specify your Africa's Talking phone number in international format // Comma separate them if they are more than one $phoneNumbers = "+254711082XYZ,+254205134XYZ"; // Specify the numbers that you want to call to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { $results = $gateway->getNumQueuedCalls($phoneNumbers); foreach ($results as $result) { echo "Phone number: " . $result->phoneNumber . "; "; echo "Queue name: " . $result->queueName . "; "; echo "Number of queued calls: " . $result->numCalls . "<br/>"; } } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while making the call: " . $e->getMessage(); } ?> </pre> </fieldset>
<?php require_once 'AfricasTalkingGateway.php'; $username = "******"; $apikey = "MyAfricasTalkingAPIKey"; $recipients = "+254711XXXYYY,+254722YYYZZZ"; // Specify your premium shortCode and keyword $shortCode = "XXXXX"; $keyword = "premiumKeyword"; // Set the bulkSMSMode flag to 0 so that the subscriber gets charged $bulkSMSMode = 0; // Create an array which would hold the following parameters: // keyword: Your premium keyword, // retryDurationInHours: The numbers of hours our API should retry to send the message // incase it doesn't go through. It is optional $options = array('keyword' => $keyword, '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($recipients, $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(); }
<?php // Be sure to include the file you've just downloaded require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "b363386c84d13496370e9a4b8ba60d8daa98e4a6a41289d392e08b2ee7996f41"; // Specify the numbers that you want to send to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) $recipients = "+255674852612"; // $recipients = "+254725813847"; // And of course we want our recipients to know what we really do // $message = "I'm a lumberjack and its ok, I sleep all night and I work all day"; $message = "Sema, huyu ni Amina. This is a test. Jibu kwa whatsapp kama umepata hii message."; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway error will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recipients, $message); foreach ($results as $result) { // status is either "Success" or "error message" 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(); }
//get some post data $callerNumber = $_POST['callerNumber']; $direction = $_POST['direction']; $sessionID = $_POST['sessionId']; $isCallActive = $_POST['isActive']; if ($isCallActive == 1 && $direction == "Inbound") { //hang up //construct response $response = '<?xml version="1.0" encoding="UTF-8"?>'; $response .= '<Response>'; $response .= '<Reject/>'; $response .= '</Response>'; header('Content-type: text/plain'); echo $response; //immediately call user back $gateway = new AfricasTalkingGateway($aitusername, $aitkey); try { $gateway->call($aitnumber, $callerNumber); } catch (Exception $e) { echo "error: " . $e->getMessage(); } } elseif ($isCallActive == 1 && $direction == "Outbound") { //redirect call to be processed on other page $url = "https://santa-slybard.c9users.io/wishlist.php"; //construct response $response = '<?xml version="1.0" encoding="UTF-8"?>'; $response .= '<Response>'; $response .= '<Redirect>' . $url . '</Redirect>'; $response .= '</Response>'; header('Content-type: text/plain'); echo $response;
try { // Make the call $gateway->call($from, $to); echo "Calls have been initiated. Time for song and dance!\n"; // Our API will now contact your callback URL once the recipient answers the call! } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while making the call: " . $e->getMessage(); } } elseif ($userResponse == "3") { $response = "END Please wait while we load your account.\n"; // Search DB and the Send Airtime $recipients = array(array("phoneNumber" => "" . $phoneNumber . "", "amount" => "KES 10")); //JSON encode $recipientStringFormat = json_encode($recipients); //Create an instance of our awesome gateway class and pass your credentials $gateway = new AfricasTalkingGateway($username, $apiKey); // Thats it, hit send and we'll take care of the rest. Any errors will be captured in the Exception class as shown below try { $results = $gateway->sendAirtime($recipientStringFormat); //Store the service details foreach ($results as $result) { $status = $result->status; $amount = $result->amount; $airtimeNo = $result->phoneNumber; $discount = $result->discount; $requestId = $result->requestId; $error = $result->errorMessage; // You can then store this information in the database for your records $dialQuery = "insert into `services`(`callSession_id`, `phoneNumber`,`service`, 'amount', 'currencyCode', 'recording')\n values('" . $requestId . "','" . $airtimeNo . "', 'Airtime top up','" . $amount . "', NULL, NULL)"; $db->query($dialQuery); }
function sendSMS($recipient, $message) { require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = ""; $recipients = $recipient; $gateway = new AfricasTalkingGateway($username, $apikey); try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recipients, $message); foreach ($results as $result) { // status is either "Success" or "error message" 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(); } }
function sms($to, $msg) { // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway(getenv('SMS_USER'), getenv('SMS_KEY')); try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($to, $msg); if ($results) { return true; } return false; } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while sending: " . $e->getMessage(); } }
<?php // Include the helper gateway class require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "MyAfricasTalkingAPIKey"; // Specify your premium shortcode and keyword $shortCode = "XXXXX"; $keyword = "myPremiumKeyword"; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Our gateway will return 100 subscription numbers at a time back to you, starting with // what you currently believe is the lastReceivedId. Specify 0 for the first // time you access the gateway, and the ID of the last message we sent you // on subsequent results $lastReceivedId = 0; // Here is a sample of how to fetch all messages using a while loop do { $results = $gateway->fetchPremiumSubscriptions($shortCode, $keyword, $lastReceivedId); foreach ($results as $result) { echo " From: " . $result->phoneNumber; echo " id: " . $result->id; echo "\n"; $lastReceivedId = $result->id; } } while (count($results) > 0); // NOTE: Be sure to save lastReceivedId here for next time
<?php require_once "AfricasTalkingGateway.php"; //Specify your credentials $username = "******"; $apiKey = "myAfricasTalkingAPIKey"; // Specify the number that you want to subscribe // Please ensure you include the country code (+254 for Kenya in this case) $phoneNumber = "+254711YYYZZZ"; //Specify your Africa's Talking short code and keyword $shortCode = "ABCDE"; $keyword = "myKeyword"; //Create an instance of our awesome gateway class and pass your credentials $gateway = new AfricasTalkingGateway($username, $apiKey); // Thats it, hit send and we'll take care of the rest. Any errors will // be captured in the Exception class as shown below try { $result = $gateway->createSubscription($phoneNumber, $shortCode, $keyword); //Only status Success signifies the subscription was successfully echo $result->status; echo $result->description; } catch (AfricasTalkingGatewayException $e) { echo $e->getMessage(); }
<?php // Be sure to include our gateway class require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "MyAfricasTalking_APIKey"; // Specify your the url of file to be uploaded $file_url = "http://onlineMediaUrl.com/file.wav"; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { $gateway->uploadMediaFile($file_url); echo "File upload initiated. Time for song and dance!\n"; } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while uploading file: " . $e->getMessage(); }
$log_permit = $userData['view_logs']; $phone = $userData['phone']; $us = $userData['username']; $pdata = $userData['password']; } $settings = "SELECT * FROM `sms_settings`"; if ($settings_run = $db->query($settings)) { $settingvalues = $settings_run->fetch_array(); // Account settings details $as_username = $settingvalues['as_username']; $as_key = $settingvalues['as_key']; $as_sender_id = $settingvalues['as_sender_id']; $setminimum = $settingvalues['minbalance']; $security_2_factor = $settingvalues['security_2_factor']; $broadcast_authority = $settingvalues['broadcast_authority']; $password_reset_type = $settingvalues['password_reset_type']; $default_country_code = $settingvalues['default_country_code']; } $gateway = new AfricasTalkingGateway($as_username, $as_key); try { $data = $gateway->getUserData(); $bal = $data->balance; $dal = explode(".", preg_replace("/[^0-9.]/", "", $bal)); //Remove the currency prefix and spaces $mybalance = (int) $dal[0]; } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while fetching user data: " . $e->getMessage() . "\n"; } } else { header('location:sms-login.php'); }
<?php // Be sure to include our gateway class require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "MyAfricasTalking_APIKey"; // Specify your Africa's Talking phone number in international format $from = "+254711082XYZ"; // Specify the numbers that you want to call to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) $to = "+254711XXXYYY,+254733YYYZZZ"; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Make the call $gateway->call($from, $to); echo "Calls have been initiated. Time for song and dance!\n"; // Our API will now contact your callback URL once the recipient answers the call! } catch (AfricasTalkingGatewayException $e) { echo "Encountered an error while making the call: " . $e->getMessage(); }
function sendSMS($msg, $recipient) { require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = ""; $apikey = ""; // Specify the numbers that you want to send to in a comma-separated list // Please ensure you include the country code (+254 for Kenya in this case) $recipients = "+254718931397"; //$recipients = $recipient; // And of course we want our recipients to know what we really do //$message = "I'm a lumberjack and its ok, I sleep all night and I work all day"; $message = $msg; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway errors will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recipients, $message, $from); foreach ($results as $result) { // Note that only the Status "Success" means the message was sent 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!!! }
public function sendSms($recipients, $message) { // Be sure to include the file you've just downloaded require_once 'AfricasTalkingGateway.php'; // Specify your login credentials $username = "******"; $apikey = "b363386c84d13496370e9a4b8ba60d8daa98e4a6a41289d392e08b2ee7996f41"; // $recipients = "+254725813847"; // $recipients; // echo $message = "This is a test. This is victor."; // $message; // Create a new instance of our awesome gateway class $gateway = new AfricasTalkingGateway($username, $apikey); // Any gateway error will be captured by our custom Exception class below, // so wrap the call in a try-catch block try { // Thats it, hit send and we'll take care of the rest. $results = $gateway->sendMessage($recipients, $message); foreach ($results as $result) { // status is either "Success" or "error message" // echo " Number: " .$result->number; // echo " Status: " .$result->status; // echo " MessageId: " .$result->messageId; // echo " Cost: " .$result->cost."\n"; return $result->status; } } catch (AfricasTalkingGatewayException $e) { return "Encountered an error while sending: " . $e->getMessage(); } }