You need access to an SMS gateway. You can hire this access from a number of companies, usually they'll charge a subscription or usage fee. I can't recommend any, but that's what you need; heres some examples, from the first page of google results for SMS gateway: http://www.clickatell.com/ http://www.ozeki.hu/ ** , and this page has some comparisons : http://www.developershome.com/sms/smsGatewayProvComp.asp . This assumes that your target audience is in a country that uses SMS for mobile text messages..
The code you use would depend on the gateway service, they'll likely have their own access/security protocol and provide specific developer instructions.
** hm, I had a look at this one again, it's not a rented service, it lets you use your phone/sim/contract as an SMS server; which is a different approach; probably not useful for high volumes of texts, but perhaps worth looking at.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
Google PHP form mail, you will find some free PHP scripts and form templates that you can customize to suit your needs.
Using the form and PHP scripts, send the PHP mailer the address to send your message to by having the user input their 10 digit phone number and selecting their carrier, put the email address together like this:
"10 digit phone number@carrier"
where carrier is:
AT&T @mobile.att.net
Alltel @message.alltel.com
Cingular @mobile.mycingular.com
Nextel @messaging.nextel.com
Sprint @messaging.sprintpcs.com
SunCom @tms.suncom.com
T-mobile @tmomail.net
VoiceStream @voicestream.net
Verizon @vtext.com
I tried this with my PHP mailer and phone carrier "7758675309@mobile.mysingular.com", passed that as the email address to the PHP script and it worked like a charm, you don't need to subscribe to anything or pay anyone any money, you simply need your HTML form that submits to a PHP mailer (or other cgi mailer, I just prefer PHP).
You will want to spend some time reading about different PHP mailer scripts and the security risks involved and how to minimize that risk, especially since you are allowing the TO address to be generated client side, you run the risk of getting hijacked by spammers using your form mailer to do their dirty work.
If you find an HTML form and PHP script to try out but need some help, let me know, I will see if I can help you out with it.
HazardTW
Junior Poster in Training
71 posts since Sep 2007
Reputation Points: 37
Solved Threads: 3
Looking at the PHP mailer scripts I have, there is a lot of unnecessary code so I just made a stripped down script that does the task with the exception of validating the user input of the 10-digit phone number, you would want to strip an NaN chars out of it and make sure you had 10 numbers left to build the TO address.
The form will submit to "phpmailer.php" the user-input, and a value that the php script will use to determine the rest of the TO address, I did it this way to avoid building the TO address client side where you do not have strict control of the data.
Here is the simple HTML form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="phpmailer.php" method="post" name="theform">
<p>
<input type="hidden" name="redirect" value="message_success.php">
<input type="text" name="10digit"> Enter your 10-digit cell number
<select name="carrier">
<option value="att">AT&T</option>
<option value="alltel">Alltel</option>
<option value="cingular">Cingular</option>
<option value="nextel">Nextel</option>
<option value="sprint">Sprint</option>
<option value="suncom">SunCom</option>
<option value="tmobile">T-mobile</option>
<option value="voicestream">VoiceStream</option>
<option value="verizon">Verizon</option>
</select>Select your carrier
<input type="submit" value="submit" name="submit">
</p>
</form>
</body>
</html>
In the php mail script we control the building of the TO address, I did not add 10-digit user-input verification, this script the way it is uses the raw user-input, you would absolutely want to verify this however you see fit.
The script:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<p>
<?php
if (!isset($_POST['submit'])){error("Must use form to get here!");}
$ph = $_POST['10digit'];//get the users phone number from the form
$carrier = $_POST['carrier'];//get the carrier
// we will build the send-to address here in php instead of letting it be generated client-side
// this will restrict the mailer to only sending the canned message to a 10 digit phone on one
// of the specified carrier networks
// you will want to add some kind of validation of the 10-digit phone number here, ie. make sure
// it is 10 digits long, only contains digits, remove and alpha chars etc.
// now lets build the email address depending on the selected carrier
switch ($carrier){
case 'att':
$to = $ph . '@mobile.att.net';
break;
case 'alltel':
$to = $ph . '@message.alltel.com';
break;
case 'cingular':
$to = $ph . '@mobile.mycingular.com';
break;
case 'nextel':
$to = $ph . '@messaging.nextel.com';
break;
case 'sprint':
$to = $ph . '@messaging.sprintpcs.com';
break;
case 'suncom':
$to = $ph . '@tms.suncom.com';
break;
case 'tmobile':
$to = $ph . '@tmomail.net';
break;
case 'voicestream':
$to = $ph . '@voicestream.net';
break;
case 'verizon':
$to = $ph . '@vtext.com';
break;
default:
error("No carrier selected, message not sent!");
}
// create our canned message
$message = "http://www.mymobilewebsite.com/";
// and the subject line
$subject = "URL to mobile website.";
// need a 'from' header
$from = "From: webmaster@mymobilewebsite.com";
// send the mail
mail($to, $subject, $message, $from);
// you may want to redirect to another page after successfull mailing, or provide a 'back' link
echo "Your message has been sent!";
exit();
// the error function that will echo your error message
function error($msg){
echo "An error has occurred: ".$msg;
exit();
}
?>
</p>
</body>
</html>
Just for simplicity I just put this in html and echoed success or failure, you might want to redirect or put in a back link.
I tested this with my cell phone on the cingular network and it worked just fine.
Hopefully some PHP experts can advice on security risks.
Good luck.
HazardTW
Junior Poster in Training
71 posts since Sep 2007
Reputation Points: 37
Solved Threads: 3