Advertisement
musioks

Africastalking

Jun 12th, 2017
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.27 KB | None | 0 0
  1. <?php
  2. $DB_host = "localhost";
  3. $DB_user = "root";
  4. $DB_pass = "";
  5. $DB_name = "shareride";
  6.  
  7. try
  8. {
  9.     $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  10.     $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. }
  12. catch(PDOException $e)
  13. {
  14.     echo $e->getMessage();
  15. }
  16. $sql=$DB_con->prepare("SELECT name,phone FROM users");
  17. $sql->execute();
  18. $fetch=$sql->fetchAll();
  19. foreach($fetch as $rows){
  20.     $phone[]=$rows['phone'];
  21. }
  22. $numbers=implode(", ",$phone);
  23.  
  24. // Be sure to include the file you've just downloaded
  25. require_once('AfricasTalkingGateway.php');
  26. // Specify your login credentials
  27. $username   = "mukandi";
  28. $apikey     = "f239448f85c09f2c877794a61d36ac7300584845201c684820f77dd70e9ce882";
  29. // NOTE: If connecting to the sandbox, please use your sandbox login credentials
  30. // Specify the numbers that you want to send to in a comma-separated list
  31. // Please ensure you include the country code (+254 for Kenya in this case)
  32. $recipients = $numbers;
  33. // And of course we want our recipients to know what we really do
  34. $message    = "Niaje Wasee, This is David Musyoka. Am just testing africastalking message API. Ndio inafanya";
  35. // Create a new instance of our awesome gateway class
  36. $gateway    = new AfricasTalkingGateway($username, $apikey);
  37. // NOTE: If connecting to the sandbox, please add the sandbox flag to the constructor:
  38. /*************************************************************************************
  39.              ****SANDBOX****
  40. $gateway    = new AfricasTalkingGateway($username, $apiKey, "sandbox");
  41. **************************************************************************************/
  42. // Any gateway error will be captured by our custom Exception class below,
  43. // so wrap the call in a try-catch block
  44. try
  45. {
  46.   // Thats it, hit send and we'll take care of the rest.
  47.   $results = $gateway->sendMessage($recipients, $message);
  48.            
  49.   foreach($results as $result) {
  50.     // status is either "Success" or "error message"
  51.     echo " Number: " .$result->number;
  52.     echo " Status: " .$result->status;
  53.     echo " MessageId: " .$result->messageId;
  54.     echo " Cost: "   .$result->cost."\n";
  55.   }
  56. }
  57. catch ( AfricasTalkingGatewayException $e )
  58. {
  59.   echo "Encountered an error while sending: ".$e->getMessage();
  60. }
  61. // DONE!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement