WAP: Part 4 - Send SMS from PHP

Finally, let's send SMS messages to mobile phones with links in them. This is the most simple and most reliable way to get a URL to a phone. Most modern phones are smart enough to be able to pick out a URL and give you an option to visit it. Granted, the "GOTO" option may be buried in a menu somewhere, but for now it's the best we can do to reach the broadest audience.

If you haven't set up Kannel yet, you'll want to do that. You can refer to my previous article WAP: Part 2 - Send SMS from Kannel. It includes information on a basic setup and also how to send a test SMS message on the command line so you know it works before we get into doing with PHP.

This process is also the easiest to construct using PHP. Since Kannel does all of it's calls using the HTTP protocol, we'll simply turn on allow_url_fopen in our PHP ini and then we can use file() to make the Kannel requests. You could also use curl or a socket connection if you'd like.

Since this example so simple, I'll let you download the example code to look at the actual call, but essentially we're doing:

<?php

$result = file(
    'http://localhost:13013/cgi-bin/sendsms' .
    '?user=sms_user' .
    '&pass=sms_pass' .
    '&to=7025551212' .
    '&text=Go+to+Yahoo%21+on+your+phone+by+visiting+http%3A%2F%2Fwap.yahoo.com'
);

?>

If you're using the example index to send, don't forget to change the message to include the URL in the message itself. Unlike sending a
WAP Push message, there is no URL directly associated with the message.

Download the example

Articles In This Series:


WAP: Part 1 - MultiTech USB GPRS Modem in Linux
WAP: Part 2 - Send SMS from Kannel
WAP: Part 3 - WAP Push with Kannel & PHP
WAP: Part 4 - Send SMS from PHP
WAP: Part 5 - Customizing content with WURFL
WAP: Part 6 - Microbrowser content in WML / XHTML MP

Leave a comment

You must be logged in to post a comment.