Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Created October 3, 2012 21:43
Show Gist options
  • Save TMcManus/3830062 to your computer and use it in GitHub Desktop.
Save TMcManus/3830062 to your computer and use it in GitHub Desktop.
How to send SMS Messages from a pool of numbers
<?php
// Sending SMS messages from a pool of numbers
// Load the Twilio PHP Helper Library
// This library can be downloaded from: https://github.com/twilio/twilio-php
require('Services/Twilio.php');
// Fill in your account credentials
$sid = "ACXXXXXXX"; // Your Account SID from www.twilio.com/user/account
$token = "YYYYYYY"; // Your Auth Token from www.twilio.com/user/account
// Build an array with all the numbers you'll be sending to and from
$from_numbers = array('+17075551234', '+17075552345', '+17075553456'); // Replace with your own Twilio Numbers
$to_numbers = array('+12345678900', '+12345678901', '+12345678902', '+12345678903', '+12345678904');
$message = "Due to the inclement whether, school has been canceled for today.";
// Initialize Twilio PHP Helper Library
$client = new Services_Twilio($sid, $token);
// Send the messages
foreach($to_numbers as $to_number){
$from_number = $from_numbers[array_rand($from_numbers)];
try{
$message = $client->account->sms_messages->create(
$from_number, $to_number, $message
);
} catch (Exception $e){
// Because it's a good idea to catch and log your errors
error_log("From: ".$from_number." | To: ".$to_number." | Send Failed: ".$e->getMessage());
}
}
echo "Sent";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment