Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $DB_host = "localhost";
- $DB_user = "root";
- $DB_pass = "";
- $DB_name = "shareride";
- try
- {
- $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
- $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- $sql=$DB_con->prepare("SELECT name,phone FROM users");
- $sql->execute();
- $fetch=$sql->fetchAll();
- foreach($fetch as $rows){
- $phone[]=$rows['phone'];
- }
- $numbers=implode(", ",$phone);
- // Be sure to include the file you've just downloaded
- require_once('AfricasTalkingGateway.php');
- // Specify your login credentials
- $username = "mukandi";
- $apikey = "f239448f85c09f2c877794a61d36ac7300584845201c684820f77dd70e9ce882";
- // NOTE: If connecting to the sandbox, please use your sandbox login credentials
- // 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 = $numbers;
- // And of course we want our recipients to know what we really do
- $message = "Niaje Wasee, This is David Musyoka. Am just testing africastalking message API. Ndio inafanya";
- // Create a new instance of our awesome gateway class
- $gateway = new AfricasTalkingGateway($username, $apikey);
- // NOTE: If connecting to the sandbox, please add the sandbox flag to the constructor:
- /*************************************************************************************
- ****SANDBOX****
- $gateway = new AfricasTalkingGateway($username, $apiKey, "sandbox");
- **************************************************************************************/
- // 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();
- }
- // DONE!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement