Open Source SMS Text Messaging Application
I recently built a basic SMS text message delivery application designed for a local broadcast television station to send breaking weather and traffic alerts to the mobile devices of subscribers to the free service. I learned some things along the way and wanted to share a quick overview of how the application was put together.
First, this approach is designed for those wanting to deliver SMS text messages in the United States. In the US, the system is open to senders to send text messages to mobile devices with no charge to the sender. Those on the receiving end of the text message are billed according to the particular service plan they have with carrier. The main point to remember here is that those who receive text messages are usually billed in some form or fashion so be sure they really want to receive what you are sending.
I believe SMS billing is handled differently is many overseas markets, where both the sender and receiver are billed, so be sure and investigate for yourself if you are outside of the US.
The US mobile carriers make it possible to do this because each mobile device has a unique email address that when delivered through the providers website will be sent as an SMS message to the mobile device. Note: this email address is different than the standard email address many mobile devices are also issued. For all of the carriers the addresses are constructed pretty much the same way.
10 digit mobile number at special sms address .com
For instance, Sprint’s special SMS messaging address is
messaging.sprintpcs.com
So, a Sprint mobile user with the phone number 123 456 7890 could be sent a SMS text message at the address
1234567890 @ messaging.sprintpcs.com
A somewhat comprehensive list of these SMS addresses for US mobile carriers can be found here among other places.
OK, so now that we know how to communicate with the mobile device the next step is to build a couple of small applications with PHP and MySQL that allow your customer or audience to sign up and receive your mobile alerts. Please remember, MOBILE ALERTS ARE OPT IN ONLY. Spam is evil whether it is delivered to your inbox or your phone.
First — the signup form:
To get started, on a FreeBSD Apache virtual server I used PHPMyAdmin to create a new MySQL database called newsalerts. In this database I created a table called subscriptions. In this table I created 3 fields: mobilenumber, provider, smsaddress.
From there I used PHP to build the database front end sign up form. Here’s a screenshot:

This is a relatively straightforward PHP database signup application with a little extra bit in there that combines the three sections of the phone number, adds an @ sign and the carrier address info to create the complete SMS address for that device.
The second part of the process is an application that allows the meteorologist or traffic reporter to enter a message title and the text message to send. When they press send, the application will then loop through the database of subscribers and deliver that message they created via SMS to each subscriber.
Here is a screenshot of this part of the application:

The message can be up to 160 total characters in length (assuming 7 bit characters). The user can also simply send a URL link if they want to send the subscriber to a more graphically rich mobile site that might include a radar map or a picture of an auto accident.
IMPORTANT — anyone with access to this part of the application can send alerts to all of your customers so if you are building something like this you will definitely want to use .htaccess or some other method to password protect this part of your application.
Both parts of this application use the PHPMailer open source application to handle the mail process and rely on PHPMailer’s class.phpmailer.php.
Now for a couple possible downsides to this approach:
First, most of the mobile carriers warn that SMS text message delivery using this process can be delayed, but with all my tests to date, delivery of the text message has taken less than two minutes, most all under a minute and many times delivery to the device is just a matter of seconds.
Second, as stated earlier, you are restricted to sending only 160 characters of text via this method. No MMS messaging via these protocols. This does limit you somewhat but doesn’t really strike me as an obstacle since if your content involves more than just text, then you can simply send your user a link to your rich mobile content that they can then download. This seems like a reasonable workaround in most cases.
To recap, by taking advantage of open source tools and techniques like these just about any type of content developer or small business can take advantage of mobile devices to help build relationships with your audience or customers.
And here’s a thought, if your business model involves your audience or customer paying to receive your content, then you can team this approach up with the Paypal Monthly Subscription Option and you are ready to go with an entry level SMS content distribution strategy.
Update: If you’re working on delivering audio or video to mobile devices, be sure and read about the mobile carriers and devices we tested in the post Delivering 3GP and MP3 Content with SMS Text Messaging.
We have been experiencing problems specifically with Sprint phones receiving our text messages. Have you found any particular problem with sprint phones?
I’ve had good luck with Sprint as far as receiving messages sent with this app and knowing what to do when you only send a link.
Not sure it is related to the issues you are running into with Sprint, but there is a conversation going on in the Sprint Developers Forum (developer.sprint.com) about some changes Sprint may have made in their WAP Gateway and its impact on some WAP sites.
One situation that has surfaced is the way some carriers and devices appear to handle any links that are sent via SMS. In some of the carriers on some of the devices that have been tested so far, URL’s aren’t hot when the user opens the SMS message and need to be cut and pasted into the phones wap browser. It appears to be the minority of cases, but that is something that has popped up.
This is a great article. I implemented something like this myself, but there were a few limitations to get around, and I would like your input on how you handled these:
1. This solution requires that you know the carrier as well as the phone number, so you can locate the right SMTP server. Because of this, the user wishing to receive the message must subscribe first with this information.
2. Because users can change networks now without changing their cell phone numbers, this makes it difficult to keep this information in sync unless the user helps.
3. If you wish to implement something that allows the user to send text messages to any number (not just ones that are registered with your application), they must know the carrier.
Have you found any solutions to these problems that don’t involve purchasing expensive libraries that basically hard code the SMS gateway addresses (and thus can get out of sync and require lots of maintenance after you pay a lot of money)?
Hi Travis:
Thanks for the questions. You’re right on target. When the subscriber signs up they have to provide their mobile number and the mobile carrier they are with and if they move their number to a new carrier then they need to update their subscription.
Have not found a way around this, but for apps in the subscription/registration model (paid or free) and within a certain scale the tradeoffs seem manageable. In the scenario that you give in example 3 with an open setup with no registration, no knowledge of the carrier and a potentially very large scale this approach no doubt becomes difficult if not near impossible to implement.
To use this open method for delivery, one way or another we need a database of phone numbers with corresponding mobile carriers. Either the user provides that info or we have to get it from somewhere else. If there is a reliable, manageable and affordable method of deducing the carrier (and therefore the delivery address) from the phone number alone that would be a huge plus. Since the FCC passed local number portability
that seems like a pretty big challenge though. What was once a landline could now be a Sprint phone that will tomorrow be a Cingular phone. Or vice versa.
If you find workarounds or new approaches that improve these areas I would very much like to learn about them so please check back and share what you find.
Good luck with your app Travis.
DC
Hi David,
I found your blog posting about your SMS messaging solution in the strangest way. It started out I was looking up information about ATT’s U-verse here in San Antonio. I found satechblog.com, and then somehow I found contentdeveloper.com.
Anyway your posting about delivering SMS messages immediately caught my eye. The reason is, I have done the exact same thing. In fact, my company’s business is based off of sending SMS alert messages (emergency school closing information). I live here in San Antonio,
but emergency school closings happen a lot up north, so getting this information to parents in a timely manner is important. It’s not that
critical in south Texas.
Anyway, for our first attempt at SMS messaging I did exactly what you described. That is, using the carrier’s email -> SMS gateway. The
problem was that the carrier’s gateways can be very sensitive, and start blocking your messages if they suspect it may be spam (since the user bears the cost). We were sending thousands of alert messages, and carriers (verizon in particular) started to block us. We were able to get temporarily whitelisted, but in the end we chose to go with a true SMS aggregator in order to more reliably send these messages.
I learned WAY more about SMS messaging than I cared to, but it is working for us now

Anyway, I just wanted to share that. I thought it was interesting that there was more than 1 person in San Antonio that developed such
similar SMS alert mechanisms
I will add your blog to my newsreader. Glad I found it!
Ian
(note: Ian sent these comments as an email but I wanted to share them here as I thought it might be helpful to alert you to some potential roadblocks with this approach if the open source sms service you are building is going to scale beyond a small to medium sized audience. Thanks Ian for letting me post your email and share your experience. DC)
Ian,
My business will be sending out SMS alerts and we’re trying to determine how far we can go using the carrier’s email. How much message volume did you have when they started blocking you? Who did you speak with at the carriers to get whitelisted, and how much message volume did they allow at that point before you had to get provisioned with a short code?
Thanks!
John
John - There is no exact number, but we were sending out thousands of alert messages. Verizon seemed to be the most sensitive.
Ian
hi,
your project seems very interesting. i saw this while researching for info on sms based application developing. i’ve recently made an app, on c# though, same as yours, can send and receive sms. i also used a gsm modem as the hardware part of the app.
maybe we can share insights on developing sms based applications
keep up the good work!
dave
hey
actually i had to make an application similar to this one sending messages at mobile networks, ok, i just read this article and that php and mysql thing is so simple will do that in 15 minutes, but i was just wondering what’s the actual code you wrote in php for sending those sms alerts/messages to all the email addresses in your database. kindly let me know as soon as possible
Thanks a lot for the insight into problem I have been trying to figure out.
How would one unsubscribe, directly from their phone?
For instance most SMS stuff uses a 4-5 digit number. “text unsub to 23232″
Without this capability in your method, how do you deal with people who want to unsubscribe?
Hi Guys
You may want to visit http://www.mysmsaddress.com or virtualtextmessenger.com for your group SMS requirements its a real SMS Gateway
>>How would one unsubscribe, directly from their phone?…Without this capability in your method, how do you deal with people who want to unsubscribe?<<
No doubt Chris. This is one of the challenges of this approach.
Current options for handling is letting the user unsubscribe via email sent from their phone or from browser at a URL. For users’ with newer phones, this works pretty well. Older phone users can accomplish from desktop.
Certainly not as elegant as texting “unsub” to a short code, but for a content developer with a small to medium size user base, a work around that perhaps some can live with.
Hi David,
I really enjoyed reading your post on the SMS handling system that you developed. I’m not a developer, but I’d like to create an application that allows users who sign-up via the web to receive group text messages from computers or mobile phones (also communicate via email) and have a reply-all feature on their phone. I’d like to partner with a developer / programmer….what programming languages are necessary?
Also, do you think that I should go the route of an SMS aggregator or develop our own system? If I develop my own system, how much will it cost to receive text messages? The aggregators charge one to four cents to send / receive messages.
I appreciate any insight that you can provide.
Best regards,
Scott
(note: Scott sent this via email earlier this week, and with his permission I’ve posted his questions here. Many content developers are evaluating the same decisions and it would be interesting to hear about the different directions people are going with, and why. Thanks Scott. DC)
David,
I’d like to host an app. which would have the ability to allow the client to schedule 1) phone reminders 2) email reminders 3) SMS text message reminders.
Do such an application already exist in the marketplace? Thank you in advance for your reply.
Emmett
Hi Emmett:
I don’t know of an open source turnkey app available that you can download, install and be up running right away doing exactly what you are after…yet
One approach some people have taken — many of the calendar apps have this functionality or something close to it built in. Many of them also have their API’s available to build your own add ons or hook into.
Backpack comes to mind.
http://backpackit.com/
Good luck, and let us know what you find.
DC
Hello,
I am trying to build a school closings system with NWS advisories map, php scroll, etc… plus a school closings area so that schools can post closings, and then they show up in a special format on the public side. I already have some of the interface done, just now trying to do the school closing part. I also want my closings to auto expire.
How do I go about this using MySQL and PHP?
Thanks,
Mike
Hi Mike:
You may want to take a look at what Ian is doing at School’s Out and Campus Wire.
http://www.schoolsout.com/
http://www.thecampuswire.com/
Good luck with your project.
DC
Ian,
Great to see good feedback on a technology such as SMS on your site. SMS is quickly becoming a common tool of use in our daily lives. This is proven by the recent unlimited everything offers from all the carriers.
My question is this:
Is there a way to house your own SMS gateway solution and effectively reach your targeted audience. We are looking at providing a service to communicate with thousands of people daily but the volume varies day-to-day.
Do you do anything with MMS? I would really like to explore this but am told that we should build a custom application for phones to do this…what do you think?
Craig
Craig, I haven’t done anything with MMS.
I am currently using clickatell.com for my SMS delivery.
Housing your own SMS gateway requires direct connections and agreements with the major carriers. This is probably cost prohibitive to most companies.
Great idea. I was looking for SMS info and finally stumbled across your post. I am a school teacher who is looking for ways to successfully implement cell phones in class, so our district will get over its arcane policies, and was wondering if someone would care to help a relatively novice programmer set up a system. I am strong with basic web programming, but novice with SQL and PHP, my remotely hosted site has plenty of options for the database, but any help/walkthrough would be much appreciated.
Hello Ian,
I am working on an SMS emergency alert application for my school and we are looking into using Clickatell. How happy have you been with their service? Any complaints? Would you recommend them? Do School’s Out and CampusWire both use Clickatell? I am trying to grasp the whole setup and I am wondering why should one use these when they can directly sign up with Clickatell? Could you clarify that for me?
Thanks,
Anu
BTW, great post DC.
Hi, David;
Great and helpful site. I was hoping that you could provide a little more help in the form pointing me in the right directions.
I have sms content that I believe people will be willing to pay for, per sms. Ideally, they would send a request via sms, and they would then receive my content via sms. They would pay for it, and I would get a cut, per sms.
Do you know of any services that can help me with this (I imagine they will take a cut, or include advertising)?
Not ideal, but if that doesn’t work, is there a service that will set up my content to be delivered once a person subscribes, and pays a monthly fee?
I am new to the sms business and technology side of things, but have killer content to get into the hands of users, and need help with how.
Thanks so much for any and all suggestions,
Best,
Matt