Grow your CSS skills. Land your dream job.

Last updated on:

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

Comments

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

  3. can i get the actual / full code of the send text message please…

  4. Jerbs
    Permalink to comment#

    All of your stuff is very impressive to say the least.. for texting you can also use MailUtils and SSMTP for free.

    ATT=@txt.att.net
    BOOST=@myboostmobile.com
    VERIZON=@vtext.com
    VIRGIN=@vmobl.com
    ALLTELL=@message.alltel.com

    echo “AuthUser=$AuthUser” >> /etc/ssmtp/ssmtp.conf
    echo “AuthPass=$AuthPass” >> /etc/ssmtp/ssmtp.conf
    echo “FromLineOverride=YES” >> /etc/ssmtp/ssmtp.conf
    echo “mailhub=smtp.gmail.com:587″ >> /etc/ssmtp/ssmtp.conf
    echo “useSTARTTLS=YES” >> /etc/ssmtp/ssmtp.conf

    echo $message | mail -s “$SUBJECT” $NUMBER

  5. Permalink to comment#

    This is awesome, we’ve used http://notifynotify.com to capture phone numbers and then use their platform to send them out.

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

```
<div>Example code</div>
```

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".