I've had a lot of requests to turn some of my Twitter apps into mobile services. Most companies, like Twitter itself, use Short Codes (like 40404) to accept and send txt/sms messages. Short codes are very expensive (the cheapest solution I found started at $500 per month for a randomized short code of up to 8 digits). I knew there had to be a "poor man's" way around buying a short code so I made one using PHP and IMAP.
I've only had around 200 people use it thus far but it seems to be working nicely. It's rough and can use a lot more work, but that's up to you.
You need to setup an email address for mobile users to send their messages to (I suggest m@yourdomain.com for simplicity).
<?php $mail=@imap_open("HOST","USERNAME","PASSWORD") or die("Can't connect: " . imap_last_error()); $mails=imap_num_msg($mail); if($mails==0) { die('No new texts.'); } else { echo "There are $mails new texts"; for($i=1;$i<=$mails;$i++) { $chead=imap_headerinfo($mail,$i); $mid=ltrim($chead->Msgno); /* Attempt to remove some of the garb headers and such that some providers and phones send with messages */ $tweet = substr(imap_body($mail,$mid), 0, 144); list($tweet, $trash) = split('[=]', $tweet); list($tweet, $trash) = split('Sent from', $tweet); //Now that we have the message from the user's phone, send out a return message. $from1 = $chead->from; //1 due to the probability of having a $from var already defined in your script. foreach ($from1 as $id => $object) { $toaddress = $object->mailbox . "@" . $object->host; } //Send the text message echo "Message Received: $tweet Send to $toaddress"; mail("$toaddress", "Your message receipt!", "Your tweet has been received."); echo " <hr />"; } } imap_close($mail); ?>
The only hitch is that some phones don't allow users to input symbols, or sometimes even letteres, into the to box for a text message. There's a way around that, too (if your users only think to do it). They simply need to add your email address as a contact prior to creating the message. It's the matter of simply selecting a contact to send the message to, then.
Another way around this is to send the message to the provider's SMS email gateway (I don't know all, but AT&T's is 36245). Then, in the body of the message, type "m@yourdomain.com MESSAGE HERE". The provider will automatically strip the email address from the start of the txt and send the message, minus the email address at the beginning, to said email address.
It's the long way around and I'm sure there is a simpler solution. This is my solution and it works fine for what I need it to do.






