Code Snippet

Home » Code Snippets » PHP » Send a Text Message

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 )

Reference URL

Subscribe to The Thread

  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?

  2. 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. ;)

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~