Send SMS (text messages) via PHP

TheYemboProject

I figured this out the other day and thought it would be a good idea to pass on. SMS messages are just sent to special email addresses, so they can be sent from server to phone with minimal effort. Here is the form and handler, feel free to copy or modify it in any way you see fit:

Sending a text message to a cell phone through PHP is just a matter of appending the correct suffix to the number and using the mail() function. If you want to add more carriers, go here and find the carrier you are looking for. If you do not know the carrier (ie. if you want to add a "not sure" option to the pulldown menu), add @teleflip.com as the suffix. The phone numbers must be 10 digits long (XXX-XXX-XXXX).

Feel free to contact me if you are having any trouble,
The Yembo Project

2let2sell2buy

what countries will this work with? etc...

popcop

dont think this would work in the uk

scragar

I tried the email deal, first email got no response or text, second got bounced back with the message: "this does not appear to be a valid north american phone number", so I'm guessing only U.S. no.s right?

TJ111

I don't have time to try this now, but if this works for someone let me know. If it works I might write a little Adobe Air app when I get time to text message people from my computer at work (without an IM client).

TheYemboProject

I'm in the US. Theoretically, it should work outside of the US if you use the right gateway, but I can't try it since I can't leave the US.

sekuchi

Sir, how about the opposite way. From cell to website. e.g. if the user send message, then in the website, there is a part where all the messages can be view. Any idea how to do this?

scragar

look on the wikipedia page he provided, there are 2 sites listed that do sms to email

chazzy

unfortunately, this solution makes a lot of assumptions (each phone number can be reached at an email address, service providers allow for bulk emails in this fashion, etc) that just aren't true everywhere, even inside the US.

hastx

I have had an sms form on my site for a while. The problem I run into is that many sms relays only support limited header info, which means that creating a message that can be "Replied To:" reliably when it was created from a web form is sketchy...but sending the message has worked well.

You can scale back on the coding by concatenating the number to the carrier from the web form, then the php script just ties the two together:

A few years ago I worked with for a company that developed a service with Vodafone in the UK on a reverse billing text chat service that made the company (and Vodafone) a small fortune. We paid about 4p a text and charged a lot more depending gong the service.

If you're interested in using SMS reliably you need a contract and a gateway,. For us back then it worked like this (in the UK). We advertised a short code like 8008 and a key word like 'chat' so the ad would run saying text 'chat' to 8008. The text went to Vodafone and they http posted it to us via their gateway. We stored the number in our database and used either a human operator or robot to reply (again depending on the service) using http to send to the gateway. The user would reply to the text directly and the gateway would again send through to us with their message. We wrote an interface that organized the messages for reply. It was quite a laugh as no-one had a service like that back then (around 2000) but when they also wanted an adult service the message logs became very very scary. I thought I could sue for emotional damage after a few of them.

They charged about one pound fifty a text and here's how 90&#37; of adult the conversations went.

Welcome, send you message to start chatting.
Hi whats your name?
Sally how are things with you?(1.50)
Not bad, are you feeling horny?
you bet, how about you?(1.50)
Great, what do you look like?
Blond, Petite, big boobs (1.50)
Do you take it up the arse?
You're a bit forward aren't you, is that what you like?(1.50)

nothing

That's why we wrote the robot. almost every one did the same thing and asked that same question so we though why pay a team of people when we can bot it. It didn't affect the monthly revenue at all.

We had one woman call in irate that we had show up on her bill. My boss was a very cool guy and tried to clam her down while we looked into the message logs. The call went like this

Rant... tirade.. how dare you...refund ....lawsuit etc
We don't know how it could happen it's a subscription service.
rant ... fume...
Does anyone have access you your phone
no, husband has his own ... seethe .... scream
(we check logs)
(He puts her on speaker for the whole office.)
Is your husbands name David?
.....silence.....
Hello?
...yes....
Because we have these messages ('my name Davids... messages descend into filth)
....silence.....OK thank you, goodbye.

Dam if that wasn't the funniest day in a very fun place to work!

Yelgnidroc

Take a look at bulksms.

You can incorporate into php scripts to send SMS and also receive replies back to an e-mail address.

minal

Sir, how about the opposite way. From cell to website. e.g. if the user send message, then in the website, there is a part where all the messages can be view. Any idea how to do this? i am also in search of same code can u pls tell me that it possible if yes the pls provide guid line for it .Is there any requirement of hardware or have to purchase any packages

SyCo

SMS gateway services will allow for this. you typically pay for each ext message but can upsell the value of them. Read the post above for an example service we used to run.

skilled1

protip: for us carriers 99% of text messaging can be accessed by email via

Smoke1

Hi im trying to get this to work and im not having any luck can u explain how to get this php to work ive never worked with it b4. when i hit submit the actual php file comes up and nothing happens

SyCo

So are you running this on a testing server on your PC?

You need to call the files via http://domain, on a WAMP/LAMP box probably http:/localhost/testpage.php. If you access it via the file structure like, c:\path\to\files.test.php it'll not be run through the server's php interpreter so you get the text file. You can acesss HTML via the file structure because the .html file extensin is probably associated with a browser. It'll display correctly, directly opened in a browser but PHP will not. So if you mix that up you'll get the problem you're having. An HTML page with a form with the action to a PHP page opened via the file structure in a browser. The HTML page will display but the PHP one will show as text.

Smoke1

i uploaded it to my host here is the site http://www.miamicriminallawattorney.com/sample.html it doesnt look right i know because im not @ that point yet to make it look nice im just trying to get the text thing working first. ty so very much for your information thus far.

Smoke1

this is the message i get

Method Not Allowed

The requested method POST is not allowed for the URL /scripts/send_sms.php.

i would like to do away with the carrier drop down and have that hidden along with the "to" section just a given that its going to go there so people do not abuse the texting and start using the site to text thier friends and eat up the transfer data quota.