SMS
SMS or Short Message Service is a protocol for sending short messages from mobile phones to other mobile phones. Text messaging or texting is a very popular activity worldwide, coming in only second in usage to voice calling. Approximately 50% of users worldwide have used SMS.
Due to the popularity of SMS and people's comfort with it and the fact that it enjoys a very high level of interoperability between carriers, it has been used in a variety of contexts beyond individuals messaging each-other.
Interactive Television - Voting on American Idol
Location based advertising
Daily messaging services
Microblogging - Twitter
MMS
The next step beyond SMS is MMS. MMS stands for Multimedia Messaging Service and it is a means to transmit audio, images and video via a message from a mobile phone.
More about SMS: Wikipedia: Short message service
More about MMS: Wikipedia: Multimedia Messaging Service
SMS/MMS to Email
Although it is very costly to get a shortcode (a unique SMS only number) in the US, the carriers here have implemented the ability for SMS and MMS messages to be sent to an email address.
Exploiting those capabilities for our purposes is pretty straight forward.
I put together a script in PHP which can be setup to automatically receive an email and take action on that email. The version below receives a message and then responds with an email back to the same address.
Furthermore it posts any attachments (which is how MMS message parts come via email) included in the message to a blog that you specify.
Blogging software is often feature rich and gives us a nice easy to use interface for content management. I often think of blogs as a personal CMS (content management system).
One of the earliest features of most blog software is the inclusion of an interface called XML-RPC. XML-RPC allows programmatic access to an application through HTTP and XML.
Early on, a standard for blog software using XML-RPC was developed called the MetaWeblog API. This API defined the types of queries and structure of those queries for interacting with blog software.
Through this API we can make posts, edit posts, view content and so on.
The PHP Parse Mail Script uses the PHP Pear package XML-RPC for posting to a blog:
Download it here:
PHP Parse Mail Script
Once you download this script to your desktop (and extract it) you should have a folder called "parseMailScriptPHP". Inside this folder there should be a file called "parseMailScriptPHP.php". You should open this file up in a text editor of your choice (TextWrangler on the Mac is a good choice, TextPad on Windows another good choice).
Once open, look in the script for the section that starts with this:
/* User Configurable Variables */
Below this there are variables that need to be changed in order for this script to receive your email and parse it. You should setup an email address specifically for use with this script rather than reuse an existing address. This script takes action on any email that arrives in the account and therefore you don't want it mixing with other email that you may need or not want deleted.
The script is setup to work with POP3 mail servers. Gmail uses a slightly different protocol than most normal POP3 servers and requires the "ssl://" in front of the hostname variable. Also, in order for Gmail POP3 to work, you need to enable it on your Gmail account (Settings, Forwarding and POP/IMAP, Enable POP for mail that arrives from now on).
If you are using a mail server other than Gmail, you should put those settings in the variables under this line: // Normal POP settings Be sure to comment out the Gmail specific settings and uncomment the settings that you just made:
/* User Configurable Variables */
// Gmail Settings
//$mailbox_username = "xxx@gmail.com";
//$mailbox_password = "xxx";
//$mailbox_hostname = "ssl://pop.gmail.com";
//$mailbox_port = 995; // SSL
// Normal POP settings
$mailbox_username = "xxx@xxx.com"; // CHANGE THIS LINE TO YOUR MAIL SERVER USERNAME
$mailbox_password = "xxx"; // CHANGE THIS LINE TO YOUR MAIL SERVER PASSWORD
$mailbox_hostname = "mail.xxx.com"; // CHANGE THIS LINE TO YOUR MAIL SERVER NAME
$mailbox_port = 110; // Default
The next lines that you will need to change are the next three variables, $temp_folder, $attachment_output_folder and $attachment_output_folder_relative.
The first two expect the full path to the folder on the server. In the zip file and therefore in the folder on your desktop there are folders pre-created for these purposes. You are free to use those or to create your own folder on the server.
Your variables should look something like this:
$temp_folder = "/home/xxxx/public_html/php_popper/tmp/";
$attachment_output_folder = "/home/xxxx/public_html/php_popper/posts/";
$attachment_output_folder_relative = "http://www.xxxx.com/~xxxx/php_popper/posts/";
Scrolling down through the script you will come to a portion which has the following lines:
#######
# THIS IS WHERE YOU WOULD DO SOMETHING
#######
and ends with the following lines:
#######
# YOU WOULD STOP DOING SOMETHING HERE
#######
Between these lines are the portion of the script that is responsible for posting to a blog. You need to edit the following variables with the correct information for your blog:
// Couple of variables
$blog_username = "xxxx";
$blog_password = "xxxx";
$xml_rpc_url = "/xxx/xmlrpc.php";
$blog_host = "www.xxxx.com";
The next step is to upload the contents of the entire directory up to the server. You should use an SFTP program like Fetch on the Mac or WinSCP on the PC.
Once these files are uploaded, you should log into the server using SSH. On the Mac you can do this by opening up Terminal (Applications, Utilities) and typing "ssh username@www.xxxx.com" and on windows you can use one of the SSH software options
Once connected, you will want to issue the following commands:
[xxxx@xxxx ~]$ cd public_html/php_popper
[xxxx@xxxx php_popper]$ chmod 700 parseMailScript.php
[xxxx@xxxx php_popper]$ ./parseMailScriptPHP.php
Here is a rundown: The "cd" command stands for change directory. The "chmod 700" command means make the parseMailScriptPHP.php file "read, write and execute" by you (the owner) and the "./" command means run the script.
Webmonkey has a good tutorial/article on Unix commands: Enough Unix for Your Resume as well as a nifty Unix Reference Guide.
Once you issue the command to execute the script, you should see some output like this:
Connected to ssl://pop.gmail.com
Message number: 1
from: mfargo gmail.com
Message number: 2
from: angibabez gmail.com
Message number: 3
from: newnetherland gmail.com
That's it.. Now you are receiving messages into the script and posting them to a blog