Skip to content

Instantly share code, notes, and snippets.

@caseysoftware
Last active December 18, 2015 15:39
Show Gist options
  • Select an option

  • Save caseysoftware/5806090 to your computer and use it in GitHub Desktop.

Select an option

Save caseysoftware/5806090 to your computer and use it in GitHub Desktop.
Sending an text message with PHP on Twilio
<?php
// Include the Twilio PHP library
require "Services/Twilio.php";
// Set your AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
// Instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Make an array of people we know, to send them a message:
$people = array(
"+14158675309" => "Curious George",
"+14158675310" => "Boots",
"+14158675311" => "Virgil",
);
// Loop over all our friends:
foreach ($people as $number => $name) {
$sms = $client->account->sms_messages->create(
"YYY-YYY-YYYY", // Change the 'From' number to a Twilio number you've purchased
$number, // the number we are sending to - Any phone number
"Hey $name, Monkey Party at 6PM. Bring Bananas!" // the sms body
);
echo "Sent message to $name"; // Display a confirmation message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment