Skip to content

Instantly share code, notes, and snippets.

@jmadden
Last active June 9, 2017 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmadden/d76185c7bfc02a32aba75a93513764f8 to your computer and use it in GitHub Desktop.
Save jmadden/d76185c7bfc02a32aba75a93513764f8 to your computer and use it in GitHub Desktop.
Send an SMS message through Twilio and record the message status to a log file using a Status Callback URL
<?php
$sid = $_REQUEST['MessageSid'];
$status = $_REQUEST['MessageStatus'];
$logfile = "status_callback_log.txt";
$log = fopen($logfile, 'a+');
fwrite($log, date('Y-m-d H:i:s')." SID = " . $sid . "\n");
fwrite($log, date('Y-m-d H:i:s')." Status = " . $status . "\n");
fwrite($log, "\n");
fclose($log);
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require __DIR__ . '/vendor/autoload.php'; // Loads the library. This may vary depending on how you installed the library.
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "your_account_sid";
$token = "your_auth_token";
$client = new Client($sid, $token);
$sms="Test message with a status callback URL";
$message = $client->messages->create(
'+15554442323', // TO number.
array(
'From' => '+14445559898', // From number (this must be a Twilio number).
'Body' => $sms,
'StatusCallback' => 'https://your-status-callback-url.com/record-status.php'
)
);
echo "<p>";
echo "Message SID: ".$message->sid;
echo "<br>";
echo "Status: ".$message->status;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment