Code Snippet
Send a Text Message
You'll need a TextMagic account and to download their PHP helper which they provide after signing up.
// Include the TextMagic PHP lib
require('textmagic-sms-api-php/TextMagicAPI.php');
// Set the username and password information
$username = 'myusername';
$password = 'mypassword';
// Create a new instance of TM
$router = new TextMagicAPI(array(
'username' => $username,
'password' => $password
));
// Send a text message to '999-123-4567'
$result = $router->send('Wake up!', array(9991234567), true);
// result: Result is: Array ( [messages] => Array ( [19896128] => 9991234567 ) [sent_text] => Wake up! [parts_count] => 1 )
Hi Chris, nice one. First of all thanks for such an informative post, but what if I’m using a framework for an instance CakePHP will this method work with it?
Rishi: The ‘correct’ way to do this with something like CakePHP or Zend would be to set up the TextMagic API as a third party library. But even just including it as Chris has demonstrated here would work, yes.
Framework or not, at the end of the day it’s still PHP. ;)
Thanks Vincent :-)
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.