Last active
June 9, 2017 19:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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