The "Sending free SMS online" cookbook - Part 4
Background
This article is the 4th post in a 5 part series cookbook on build a "send free sms" website. In the first post1, we explained some basics behind some of these free sites. In the second2 and third3 posts, we explained how you can use the phone companies email to SMS gateways for sending SMS
In this article, we will bring it all together and show you how to provide a simple front end web page.
Websms Form
The simplest way of allowing people to send free sms from your website is to give them a website form. The following picture shows a very simple web form and contains all the basic information that you need to collect.

Here some simple HTML that you can use or customise.
<html>
<head>
<script type="text/javascript" src="send_free_sms.js"></script>
</head>
<body>
<form action="" method="post" name="frm" id="id_frm">
<strong><?php echo $error_info;?></strong>
<table width="50%">
<tr>
<td><b>destination mobile:</b>
</td>
<td>
<input type="text" name="mobilenum" size="14" maxlength="20">
<select name="country">
<option value="" selected>In International Format
<option value="376">Andorra
<option value="61">Australia
<option value="43">Austria
<option value="994">Azerbaijan
</select>
</td>
</tr>
<tr>
<td><b>destination carrier:</b>
</td>
<td>
<SELECT name="carrier">
<option value="" selected='selected'>Please Select</option>
<option value="aliant">Aliant (NBTel, MTT, NewTel, and Island Tel)</option>
<option value="alltel">Alltel</option>
<option value="ameritech">Ameritech (ACSWireless)</option>
<option value="arch">Arch Wireless</option>
<option value="ddi">AU by KDDI</option>
<option value="beemail">BeeLine GSM</option>
<option value="bellmobilityca">Bell Mobility Canada</option>
<option value="bellsouth">Bellsouth</option>
</select>
</td>
</tr>
<tr>
<td><b>from:</b>
</td>
<td>
<input type="text" name="frommobilenum" size="15" maxlength="20">
</td>
</tr>
<tr>
<td><b>message:</b>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<textarea id="id_message_body" name="message_body" cols="80" taborder="1"
taborder="2" rows="4" wrap="Virtual" style="width: 365px"/>
</td>
</tr>
<tr>
<td>
</td>
<td align="right" >
<input name="message_count" size="3" type="text" value="136" maxlength="3" readonly>
</td>
</tr>
<tr>
<td>
</td>
<td align="right">
<input name="send_message" type="submit" value="send"/>
</td>
</tr>
</table>
</form>
</body>
</html>
Adding some handy Javascript
You can add a little javascript to this html page that provides country codes for each country and also a character counter. Obviously SMSs are limited to between 140 and 160 characters depending on the operator.
To add a country code selector just add the following Javascript handler. This calls a javascript function. We will provide you with all this code at the end of this article.
Change the select statement to include this javascript handler
<select name="country" onChange='PrefixChange(this)'>
And to add a javascript counter, change the textarea html code to call a few javascript event handlers.
<textarea id="id_message_body" name="message_body" cols="80" taborder="1"
onChange="javascript:SMSCharCounter(this,document.frm.message_count,136)"
onKeyDown="javascript:SMSCharCounter(this,document.frm.message_count,136)"
onKeyUp="javascript:SMSCharCounter(this,document.frm.message_count,136)"
taborder="2" rows="4" wrap="Virtual" style="width: 365px"/>
Adding a script handler
Now we have the webform, we will need a script that handles the web form post and then can send the message as an SMS.
The following PHP code shows you how to handle the webform post and how to call the functions to send the SMS.
<?php
// -----------------------------------------------------------------------
// This file is part of Me2Mobile
//
// Copyright (C) 2007 - 2009 Me2mobile
// http://www.me2mobile.com/
// info@me2mobile.com
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------
//Load list of email to sms providers
include "providers.inc.php";
// Handling the posting of a sms message
if (isset($_POST['send_message'])) {
// Strip all Non-Numeric Characters
$to_msisdn = $_REQUEST['mobilenum'];
$to_msisdn = ereg_replace ('[^0-9]+', '', $to_msisdn);
// Check that its at least 7 chars
if (strlen($to_msisdn)<7) {
$error_info = "Error:check your number format";
}
//check if the error is raised because number format is incorrect
if (empty($error_info)) {
$selected_provider = $_REQUEST['carrier'];
if (empty($selected_provider)) {
$error_info = "Error:No Selected Provider";
}
else {
//do a multidimensional search on the providers array
//to find the select provider
$selected = in_array_multi_key( $selected_provider, $providers);
$selected_country = $selected[0];
//Send the message using a custom function that formats the sending request
send_in_provider_format($providers,
$selected_country, $selected_provider,
$_REQUEST['message_body'],
$_REQUEST['frommobilenum'],
$_REQUEST['mobilenum']);
}
}
}
?>
Pulling it all together
We have explained the basics for sending free SMS via the free phone companies SMS gateways and we have shown you some ways to improve the success rate of using these SMS gateways. We have also shown you how to build a simple front end for your "send free sms" website. All that remains is to let you have some of our example code. I am giving you this code completely warranty free. Use it at your own risk. To the best of my ability, I will try to answer any questions/comments that you have.
Here are some files that will be useful. Note (July 2009) - I have taken them down from the site as I had a lot of interest. Contact me directly by registering on me2mobile.com and I can send this file on to you.
send_free_sms.php
providers.inc.php
send_free_sms.js
blog
Me2mobile welcomes new owner
Feb-20-2010
comments (0)
Me2mobile founders moving on!
Feb-08-2010
comments (0)
Happy New Year to all me2mobilers
Jan-06-2010
comments (0)
Your Christmas Gift - Happy Holidays
Dec-23-2009
comments (0)
New webtext service on me2mobile
Dec-16-2009
comments (0)
Texting fish in New York
Sep-29-2009
comments (0)
Twittering passengers alert to ferry delays
Sep-17-2009
comments (0)
The Joy of Text for Irish businesses
Jul-15-2009
comments (0)
Like seeing in the dark
Jul-03-2009
comments (0)
Hello World
Jun-15-2009
comments (1)
