How to send text messages (SMS) to mobile phones via the internet

Sending SMS text messages over the internet is fairly straightforward process from the point of view of the web developer and you’ll be glad to hear that it is reasonably easy to build an application which sends SMS text messages across the internet. In this tutorial I’m going to quickly brush over a few of the fundamentals that you should be aware of before attempting to build a web application that sends SMS text messages over the internet.  By the end of this tutorial you should have a clear understanding of how the process of sending text messages across the internet works and you should have a clear idea of what you have to do to get your SMS text messaging application working.

Unfortunately I have to begin this tutorial with two pieces of bad news. The first piece of bad news is that in order to build applications with SMS sending functionality you need to sign up with a company that provides text messages services for web developers and website owners who wish to tap into the SMS text messaging online craze. This costs money. A search on Google for anything that relates to “sending SMS text messages over the internet” (or any term of that nature) will light up your screen with an inexhaustible supply of companies who appear to be offering this service for free (many of these companies are investing heavily in Google ad clicks campaigns and will appear on the right hand margin of your search engine results page). Please allow me to save you some time and a little heartache by telling you now that NOBODY offers this service for free. Many may offer you a month’s worth of SMS text messaging credit for free. Some may even give you several hundred SMS “credits” from of charge. But please do not be fooled into believing that you will be able to get this service as a freebie.  Ultimately at some point you WILL have to fork out some cash if you want to build any kind of semi serious web application with SMS functionality.

The second piece of bad news I have to give you is the news that I can only really skim the surface of how to build a website that sends SMS text messages across the internet. The reason for this is because building a web application that sends text messages to mobile phones is a bit like building a payment processing system for an online shopping cart – there are many different ways of doing it and the particular system that you build will be determined by the company whom you purchase SMS credits from. Different text messaging providers use a variety of different technologies to send messages. Some text messaging providers have pre written scripts written for a variety of web technologies (e.g.; ASP, Java, PHP etc) and all you have to do is to take your pick and tweak accordingly to fit in with your own needs.

In any case, the very first thing you will have to do before worrying about any of that is you have to find a good SMS text messaging company to sign up with. This can be a little overwhelming at first as there is a wide variety of providers to choose from. My only advice would be not to allow yourself to be lured in by cheap one time only special offers that give you the first “X” (month, 100 credits or whatever) free of charge. Like drug dealers, these companies know all they have to do is give you one brief shot of their goods and you’ll be hooked for life!

When you are checking out the companies which offer an SMS text messaging service, you’ll notice that the way they do business is to sell you “credits”. Each credit represents a single instance of a text message being sent to a mobile phone, so if you buy 200 credits then it means that your application will have enough credits to send 200 SMS text messages before running out of steam. When your SMS account starts getting low (perhaps to the last 50 or so) my experience is that the text messaging provider will normally give you a courtesy call to remind you that your credit levels are running out and to ask if you’d like to top up. The amount that you pay for each text messaging credit depends on the amount of credits you buy. So, the more credits you buy, the lower your cost per credit will be. My experience in this field is that the text messaging providers are generally quite reluctant to publish their prices on their website but as a rough guide I think you should be aiming to pay less than 5 pence (about 9 cents) for each SMS credit. A word of warning - please don’t embarrass yourself by attempting to buy a small handful of credits for a text messaging provider! The minimum amount of credits that they are willing to sell you will be around the 200 mark and the maximum of credits that they will try and sell you in one go will be around the 20,000 mark. The good news however, is that your provider will normally give you a supply of free credits to get you out of the starting blocks and to help you to build and test your application before launch. The UK based SMS provider that I recently used gave me 50 credits free of charge before I had to pay them a penny.  They did this not as part of a ploy to lure me on board, but to give me an opportunity to build and test my sms text messaging application before proceeding with an order.  This is the type of service that you should expect from your sms provider.  If they are not willing to help you during the build phase then I would advise you to look elsewhere. 

OK, onto the nuts and bolts of how it all works and for once I hope you’ll forgive me for not going into too much detail here. If your text messaging provider is any good at all then they will offer generous technical support with any web development issues you may have.  After all, it's in their interests for you to build an sms text messaging application that works properly! 

Each time your web application attempts to send an SMS text message across the internet it sends information from your website to the SMS provider’s website. The information that you have to send from your website for each text sending transaction is:

  • Your account username
  • Your password
  • A list of all the mobile phone numbers who you want to text
  • The information (text) that is to be sent to all of the mobile phones

That’s it! Once you have successfully sent the above information from your website to your SMS provider’s website then they will take care of the rest. Easy huh?

The company that I use for this service (who are going to remain safely anonymous!) have two preferred methods of sending and receiving information between my websites and theirs. One method that they like to use is XML. The other method they use involves the creation of and uploading of simple text files (such as Notepad files) from my website to theirs. At the time, I opted for the second method and I’ll quickly outline how it works here.

The SMS company I use have a folder on their website which is constantly being automatically trawled by a program that is checking for new text files. Each wave of folder checking takes about 20 seconds or so. The folder that is on their website has permissions of 777 and through the use of a script that they provided me with I am able to upload .txt files to their folder from my website. The way I do this is I have a folder on my website that spends most of it’s time sitting empty and doing nothing. However, when a text message needs to be sent I use PHP to calculate the following:

  • The mobile phone number that needs to be texted
  • The contents of the text message that I want to send

When I have this information I use PHP to create and write onto a text file called “sms_outbound”. For each mobile phone number that needs to be sent a text message there is a line of text written onto a blank text file. Each line of text contains the mobile phone number to be sent a text message along with the message that is to be sent to the number. The top of each text file will also contain the username and password for my SMS account. I can also use PHP to restrict the number of characters in each sms text message to around 80 (which is reasonable, I think).

Once the file is created and saved onto my folder I execute the script (provided by the SMS company) that uploads files from my server onto theirs. After the file has been sent there will be a response from the SMS text messaging company which either gives a thumbs up (to say that the file has uploaded successfully) or an error message (in the unlikely event that something has gone wrong).

When the file has been uploaded from your server to theirs, then your goal is to immediately delete the text file that you have just created and give the web visitor a nice thank you message to reassure them that all is well.  After this, everything that happens is in the hands of the text messaging provider. Their program will normally send your text message(s) within about 30 seconds. Sometimes however, if the network is overcrowded then it may take a little longer.  The longest I’ve ever had to wait was 30 minutes.

In terms of basic concepts that’s really all there is to it. I apologise for not delving into a mass of PHP scripts in this tutorial as I usually do but I’m sure you’ll understand my reasons for keeping everything nice and general on this occassion.

Good luck on your quest to send SMS text messages across the internet! Remember, if it gets too much for you and you need a helping hand, just ask.

Yours in web development,

David Connelly

Live Assistant

Hello there! I'm Richard and I'm your live helper for today.

How can I help you?

Quote Request

If you are looking for a quick quotation then why not submit a quote request? It only takes a few moments and we always respond quickly.