Skip to content

Instantly share code, notes, and snippets.

@TMcManus
Created March 13, 2012 00:30
Show Gist options
  • Save TMcManus/2025681 to your computer and use it in GitHub Desktop.
Save TMcManus/2025681 to your computer and use it in GitHub Desktop.
Simple Form to SMS
<form action="form_to_sms.php" method="post">
<label for="phone">Phone Number</label>
<input type="tel" name="phone"/><br/>
<label for="body">Message Body</label>
<textarea name="body" maxlength="160"></textarea><br/>
<input type="submit" />
</form>
<?php
/**
* This script requires a Twilio Account and the Twilio PHP Helper Library,
* which can be found at http://www.twilio.com/docs/libraries
*/
// Require Twilio Helper Library
require('Services/Twilio.php');
// Credentials to connect to Twilio
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXX'; // <-- Replace
$authToken = 'YYYYYYYYYYYYYYYYYYYYYY'; // <-- Replace
// Twilio number the SMS message will be from. You can only send SMS messages from a number purchased from Twilio.
$sending_number = '+15555555555'; // <-- Replace
// Create a connection to Twilio's API with credentials
$client = new Services_Twilio($accountSid, $authToken);
// Actually send the number. This is where the magic happens!
$message = $client->account->sms_messages->create(
$sending_number,
$_REQUEST['phone'],
$_REQUEST['body']
);
echo "<p>Message Sent</p>";
@Celnet-hub
Copy link

This was very helpful. Thanks

@Kai-Roma
Copy link

Hello,
Thanks for the code, this works, however how to send the Friendly name or the Alphanumeric Sender ID instead of the number?
If I replace the number with a name doesn't work.
ie:
$sending_number = 'Name'

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment