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 )

Comments

  1. User Avatar
    Rishi Kulshreshtha
    Permalink to comment#

    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. User Avatar
    Will Vincent
    Permalink to comment#

    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. User Avatar
    mymahesh11
    Permalink to comment#

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

  4. User Avatar
    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. User Avatar
    Jesse
    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.

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-closeicon-emailicon-linkicon-logo-staricon-menuicon-searchicon-staricon-tag