Not too long ago we needed a web application to send text message updates to cellphones. The application would interface with other applications and admins would need an hourly statistics report which would also include any errors, which would need to be fixed ASAP.
First, you’ll find the email address used by your carrier to send your phone messages. That’s right, we will simply be sending email using PHP’s mail() function. A nice list is available in this Wikipedia article, and contains a comprehensive listing of cellphone providers and their base email addresses. There are some pay services which provide a catch all for phone numbers and automatically determine the carrier or have alternative methods if the carrier doesn’t support SMS via email, but the free list will suffice for most people.
Now that you’ve got the email address, just add in your phone number. Some carriers have two different formats for sending SMS emails but only one of them will work for your particular cellphone. Some carriers want a 1 (or w/e your region code is) in the beginning, others don’t. Send a message to your phone from your email client first to make sure it works.
Finally, construct a function in PHP that will build the message you want to send and mail it out when you want it. Here is how your mail() function will appear:
function send_mail($message) {
$to = "9875551212@phone.carrier.com";
$subject = "System Message";
mail($to,$subject,$message);
}
And that’s all there really is to it. If you wanted a more comprehensive system, one which would provide your users the ability to select their carrier and input their phone numbers, you would want to store all of the contact SMS email addresses in a database, and a user would simply input their phone number and select their provider from a dropdown. Make sure that if you offer a service like this you require the user to enter a PIN number that you would send to their phone, that way users aren’t entering in other peoples phone numbers and abusing your service.
You would also want to make sure that your application doesn’t send out too many messages in a given amount of time as I’m sure some if not all of the providers will blackmail a server which is sending out too many messages.