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 mms.skywire.co.uk, 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.

<?php
require_once("mmsdecoder.php");
$filename = "test.mms";

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

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

// 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.


Leave a Reply