Thursday, January 24th 2008

Receiving and Decoding MMS messages using Apache
posted @ 8:02 am in [ Apache -Kannel -MBuni -MMS -Mobile -PHP ]

A quick follow onto the post below of how to use Apache to serve MMS messages, one other interesting thing you can do with Apache is use it to receive MMS messages from a phone.

Basically, this just requires a little bit of lateral thinking, and some clever PHP and then you can see exactly which headers a phone uses to create the MMS messages it sends itself – and in our case use this to work out which fields we should be including in our MMS messages.

Step 1: Configure your phone to send MMS messages to your own Apache server, not the default operator MMSC.

This really depends on what phone you have, but if you dig around in the MMS settings within the phone, you will eventually find a menu option labelled MMS Server Name or similar. On a Motorola Razor V3 for example this is in Messages -> (option menu) -> Message Setup -> Change -> Server Info ->(option menu) -> Edit -> Server Name

Change this to be your own Apache server, for example in our case, or an IP address if you have one may be even better if your operator doesn’t support DNS look-ups.

Step 2: Create your MMS on the phone

Step 3: Add you MMS receiving code to your Apache server

There’s lots of good packages out there to do this, including mBlogging software such as b2evolution and Peffisaur however for our decoding we used a nice piece of PHP coding from the following article on creating an MMSC.

Step 4: Send your message from your phone to your server

Step 5: Decode your MMS message

Now you have the MMS message as a binary file, but you really want something handy to decode it for you, so this is where a handy PHP class called MMS Decoder comes in handy. By default this reads from an HTTP stream, but with the following few modifications you can make it read from files instead.

$filename = "test.mms";

if (is_readable($filename)) {
	$handle = fopen($filename, "r");
	$mmsdata = fread($handle, filesize($filename));

// parse MMS
$mms = new MMSDecoder($mmsdata);

// The MMS is parsed, so let's get the mms data from the class by the print_r() function,echo(print_r($mms, true));


Voila! All the headers from your phone built MMS ready for you to emulate in your own messages to ensure the phone receives them.

Thursday, January 24th 2008

Serving MMS messages with Apache
posted @ 7:29 am in [ Apache -Kannel -MBuni -MMS -Mobile -PHP ]

Now you would have thought after the number of years I’ve been playing around with MMS messages, using libraries like the Nokia MMS Java library to build them and servers like Kannel (SMS) and MBuni (MMS) to serve them, that we wouldn’t have any problems trying to serve MMS content ourselves using SMS binary push and .MMS encoded files.

Well, basically we did – and it all comes down to one thing – phones needing be specifically told that .MMS messages have a certain MIME type.

Some phones, the Motorola V3 Razor for example, automatically assume that all MMS messages are going to be an acceptable type, no matter what MIME type you serve them as. Therefore using a standard Apache server, a binary created MMS file (try the Nokia MMS Java library for Java, and MMSLib for PHP to build the messages) and a binary SMS push (either made yourself or using HTTP API’s such as Clickatell’s) these phones recieve the messages just fine.

However, a lot of other phones (notably Blackberry’s and Sony Ericsson’s) require specific instructions to treat the .mms file as type application/vnd.wap.mms-message

Therefore for these phones, add into the directory where the .mms files are stored the following .htaccess file and Apache will start serving the content in exactly the right way.

AddType application/vnd.wap.mms-message mms

Job done – and I bet if you’re reading because this is what you’re trying to do, we hopefully just saved you hours of going mad!