tags:

views:

2927

answers:

14

I just want to send SMS from my web application in PHP. Can anyone tell me how to do this? What all things I need to do for this?

A: 

Check if any of these resources are of any help.

PEZ
A: 

Basically, each carrier has a email gateway to which you will need to send an email. You will need to know the carrier in advance so that you know which email address to send the SMS message.

Ariel
+2  A: 

If you need a reliable way to send many SMS, you should look for a SMS service provider that acts as a web to SMS gateway. In that case there will be a http based interface, allowing you to send SMS by calling a URL and passing recipient and message as parameters.

lcvinny
+1  A: 

We use a commercial solution called TextAnywhere for this.

For a small fee (a few pence per SMS), they give you a Web service (plus APIs for .NET, ASP, Java, C++, etc.). It's easy and it works, although it's not free.

At its most basic, it's as simple as making a URL request with the number and the message text in the QueryString, and their server does the rest for you.

Dylan Beattie
A: 

There are several SMPP libraries available for PHP, one is the following. This is the protocol used to communicate with an SMS server.

http://pear.php.net/reference/Net_SMPP-0.4.3/Net_SMPP/_SMPP_Net_SMPP-0.4.3_SMPP_php.html

ng
+15  A: 

Your main option for sending SMS messages is using an existing SMS provider. In my experience (which is extensive with SMS messaging web applications), you will often find that negotiating with different providers is the best way to get the best deal for your application.

Different providers often offer different services, and different features. My favourite provider, and indeed, the one that has happily negotiated with me for lower rates in the past, is TM4B (http://www.tm4b.com). These guys have excellent rates, cover a huge proportion of the globe, and have excellent customer service.

Below is some code extracted (and some parts obfuscated) from one of my live web applications, for sending a simple message via their API:

require_once("tm4b.lib.php");
$smsEngine = new tm4b();

// Prepare the array for sending
$smsRequest["username"] = "YOURUNAME";
$smsRequest["password"] = "YOURPWORD";
$smsRequest["to"] = "+441234554443";
$smsRequest["from"] = "ME!";
$smsRequest["msg"] = "Hello, test message!";

// Do the actual sending
$smsResult = $smsEngine->ClientAPI($smsRequest);

// Check the result
if( $smsResult['status'] == "ok" ) {
    print "Message sent!";
} else {
    print "Message not sent.";
}

Many other providers that I've used in the past, have very similar interfaces, and all are really competitive when it comes to pricing. You simply have to look around for a provider that suits your needs.

In regard to cost, you're looking at prices ranging from a few pence/cents for most Western countries (prices are a little bit higher for most third-world countries, though, so beware). Most providers you will have to pay in bulk, if you want decent rates from them, but they'll often negotiate with you for 'smaller-than-usual' batches. Most providers do offer a post-pay option, but only when you've successfully completed a few transactions with them... others offer it from the start, but the prices are extortionate.

James Burgess
Do you know of any provider in USA?
Saif Khan
I don't know of any based directly in the USA... but most will send to the USA for very competitive rates, as the good providers do deals on a country-by-country local basis.
James Burgess
+24  A: 

I don't know if this applies to you, but what I have done many times to save myself the money is ask the user in his profile what his carrier is, then tried matching it with this list. Essentially, many/most carriers have an email address connected to a phone number that will easily let you send texts to the number. For example, if you have ATT and your phone number is 786-262-8344, an email to [email protected] will send you a text message with the subject/body of the email, free of charge. This technique will pretty much cover all of your US users for free. Obviously, depending on the needs of your application this may not be possible/adequate/desired, but it is an option to be aware of.

Paolo Bergantino
A: 

I had to implement user-initated sms functionality on our website recently and found the www.dotgo.com service helpful. It's free... looks like it was created by a couple of PhD's as a sort of stateless messaging framework of sorts (think http request-response model).

To get it working you set up an "index.crml" file (similar to index.html, php, etc). Ours looks like this (sorry all putting it all on one one line... having some issues getting it to display otherwise):

<?xml version="1.0" encoding="UTF-8"?><cmrl xmlns:dotgo="http://dotgo.com/cmrl/1.0"&gt;&lt;match pattern="*"><engine href="http://www.bulbstorm.com/sms/flashbulb.php"/&gt;&lt;/match&gt;&lt;/cmrl&gt;

On our site, the index file in turn references the /sms/flashbulb.php file, which (excluding opening and closing php tags) looks like this:

$wordArray = explode(' ',$_REQUEST['sys_argument']);
$username = strip_tags($wordArray[0]);
$messageBody = str_replace($username.' ', '', $_REQUEST['sys_argument']);
require_once 'Database.php';
$dbh = new Database('bulbstorm');
$args = array($username, $messageBody);
$dbh->execMysqlProc('uspAddFlashbulb', $args);
print "<message><content>Bulb received and saved to your account</content></message>";

Anyway, I only include the code to give some sense of how the framework functions and how little code there is to write to get something functional.

There are some limitations. The foremost being that everything is user-initated. So if you're primarily looking to send outgoing messages that are not preceded by your user sending a message to your site to "get" the response message then it's probably not what you want. Worked for what we were doing though. One of the founders even personally responded to an emailed question and was very helpful.

One of the features that we haven't used yet, but have considered is their subscription functionality... where users can set it up so that the dotgo system periodically polls a page on your site, sending an sms message to their phone per the schedule the user specifies. Again, I didn't take it that far, but thought it was interesting.

codemonkey
A: 

Hi could you please explain more about the dotgo engine you created and what i need to modify to use it and such? thabnk you so much!

nothign there:(what i am trying to do is use the dotgo service but i need to have a local web version to update it without having to go in to the server and change the cmrl file, i knwo it can be done ive seen it just need a sample to modify:) thank you!
+5  A: 

Send only, but cheap and easy

The simplest way is definitely using the email hack that @Paolo Bergantino mentioned above. It's easy to ask your users to type in their phone number and select their carrier from a list. It's also easy, on absolutely any development platform, to send email once you have the user's info.

There are two very important limitations that I've discovered with that approach, however:

  1. The first is that the cellular carriers all prioritize SMS messages sent through their email gateways below other SMS traffic. Probably because they aren't getting paid by the sender for these. Don't use this method if minimizing latency is important to you.
  2. The second is that especially in this modern era of portable phone numbers, users will switch carriers from time to time, and will almost certainly forget to tell you. If you need to be able to reliably deliver SMS messages to the same people a year or two from now, this method will begin to fail.

Send and receive for cheap

If you're trying to set your site up to send and receive SMS messages on a budget, you can use a service such as TextMarks. TextMarks lets you pick a keyword for your service that allows users to route messages to you through TextMarks' shared short code, 41411. The catch here is that they reserve 20 characters in each message for short advertisements to pay for their services.

Professional quality

If you require low latency, high reliability, and no advertising, you'll pretty much have to go through an SMS aggregator unless you're big enough to negotiate with each carrier individually.

The biggest thing I've found to watch out for with SMS aggregators is that many of them are really set up to be marketing companies, not application hosts--they don't really understand using SMS as a channel through which users can interact with service providers. I've found that the aggregators that use the phrase "your campaign" rather than "your application" are the worst offenders. Stay away from them, and find an aggregator that understands your needs as an application developer.

sblom
A: 

I appreciate those, however i really need to use the dotgo free service to do what i need..

so the way that works is you have a cmrl file and you need to update it via the html.. well i need to have some sort of cgi script to use where i can go into a browser window like this and type in and it woudl update the cmrl file!

make sense?? thank you!

+2  A: 

If you know the carrier, you are golden. Most have email gateways. If not you can use Clickatell API which costs about $0.04 per message. I am looking into a hack now where you would use a GSM modem and your individual cell phone plan with unlimited SMS. This could save a lot of money if it works.

Tony
I'm using ClickATell as well and I'm happy with their service.
Alex
A: 

@mash http://dktext.com/

anon
+3  A: 

Twilio recently released an API to send SMS messages. The api is rather simple, basic REST interface to send SMS, and a post returning document to respond.

Tim Lytle