Created
March 13, 2012 00:30
-
-
Save TMcManus/2025681 to your computer and use it in GitHub Desktop.
Simple Form to SMS
This file contains hidden or 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
<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> |
This file contains hidden or 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 | |
/** | |
* 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>"; |
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
This was very helpful. Thanks