You are here:
ActiveXperts.com > SMS and MMS Toolkit > How to Use the SMS and MMS Toolkit > GSM/GPRS (MM1) > PHP
Quicklinks
The SMS and MMS Toolkit is a software development kit (SDK) to enhance an application or script with SMS, MMS and Pager functionality. SMS messages can be sent using a GSM/GPRS modem, an SMPP provider, an HTTP compliant SMS provider or using a standard dialup or fixed-line SMS modem. MMS messages can be sent via a GSM/GPRS modem (MM1), an SMTP server (MM4) or an XML/SOAP compliant provider (MM7).
SMS features:
MMS features:
Pager features:
This document describes how the SMS and MMS Toolkit can be integrated into PHP projects.
Download the SMS and MMS Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
You must use the following code to declare the COM object(s) in PHP: Use the following PHP code to declare and create the MM1 object:
$objMm1Protocol = new Com("ActiveXperts.MmsProtocolMm1");
Insert the following line to declare and create the MmsMessage object:
$objMessage = new Com("ActiveXperts.MmsMessage");
Insert the following line to declare and create the MmsSlide object:
$objSlide = new Com("ActiveXperts.MmsSlide");
Insert the following line to declare and create the MmsConstants object:
$objConstants = new Com("ActiveXperts.MmsConstants");
To send an MMS the toolkit requires following information:
Create a simple form which collects this information from the user. Note that the APN settings, WAP Gateway and MMSC Addresses are also stored in configuration files which are shipped with the product. You can also configure your MMS settings using these configuration files. They can be found in the install directory of the SMS and MMS Toolkit in the "Provider" folder.
The toolkit allows you to preview all connected modems. The following code returns an array of connected devices:
//******************************************************************************
// This function returns an array which contains all connected devices
function getDevices(){
global $objMm1Protocol;
$intDevices = $objMm1Protocol->GetDeviceCount();
$arrDevices[0] = "No devices detected";
for( $i = 0; $i < $intDevices; $i++ ){
$arrDevices[$i] = $objMm1Protocol->GetDevice($i);
}
return $arrDevices;
}
Use the following code to list the array in a combobox:
<select name="CTL_DEVICES" style="width: 250px">
<?
foreach( getDevices() as $device ){
echo "<option>" . $device . "</option>";
}
?>
</select>
If the instances described in step 2 can successfully be created, you can now send MMS messages using a connected GSM GPRS/EDGE/UMTS modem.
The following PHP code is the core of a website where the user can fill a file located on the webserver, and send it as a MMS message to his mobile phone or email address.
The demo can be run from a client connecting to the PHP webserver. The client does not need any additional hardware. The modem has to be connected to the webserver.
The following PHP code shows how to send a MMS:
$objMm1Protocol = new Com("ActiveXperts.MmsProtocolMm1");
$objMessage = new Com("ActiveXperts.MmsMessage");
$objSlide = new Com("ActiveXperts.MmsSlide");
$objConstants = new Com("ActiveXperts.MmsConstants");
$CTL_SERVER = "[HOST]";
$CTL_APN = "[APN]";
$CTL_GATEWAY = "[GATEWAY]";
$CTL_ATTACHMENT = @"C:\Windows\Clock.avi";
$CTL_MESSAGE = "[MESSAGE]";
$objMm1Protocol->LogFile = "C:\logfile.txt";
if( $_POST["CTL_SEND"] != "" ){
$CTL_SERVER = $_POST["CTL_SERVER"];
$CTL_APN = $_POST["CTL_APN"];
$CTL_GATEWAY = $_POST["CTL_GATEWAY"];
$CTL_ATTACHMENT = $_POST["CTL_ATTACHMENT"];
$CTL_MESSAGE = $_POST["CTL_MESSAGE"];
$objSlide->Clear();
$objSlide->AddText( $CTL_MESSAGE );
$objSlide->AddAttachment( $CTL_ATTACHMENT , 0 );
$objMessage->Clear();
$objMessage->AddRecipient( $_POST["CTL_RECIPIENT"], $objConstants->asMMS_RECIPIENT_TO );
$objMessage->From = $_POST["CTL_SENDER"];
$objMessage->Subject = $_POST["CTL_SUBJECT"];
$objMessage->AddSlide( $objSlide );
$objMm1Protocol->Clear();
$objMm1Protocol->Device = $_POST["CTL_DEVICES"];
$objMm1Protocol->ProviderMMSC = $CTL_SERVER;
$objMm1Protocol->ProviderAPN = $CTL_APN;
$objMm1Protocol->ProviderAPNAccount = $_POST["CTL_APNACCOUNT"];
$objMm1Protocol->ProviderAPNPassword = $_POST["CTL_APNPASSWORD"];
$objMm1Protocol->ProviderWAPGateway = $CTL_GATEWAY;
if( $_POST["CTL_PINCODE"] != "" ){
$objMm1Protocol->EnterPin( $_POST["CTL_PINCODE"] );
}
if( $objMm1Protocol->LastError == 0 ){
$objMm1Protocol->Connect();
}
if( $objMm1Protocol->LastError == 0 ){
$objMm1Protocol->Send( $objMessage );
}
$numLastError = $objMm1Protocol->LastError;
$strLastError = $objMm1Protocol->GetErrorDescription( $numLastError );
$strLastResponse = $objMm1Protocol->ProviderResponse;
$objMm1Protocol->Disconnect();
}
//******************************************************************************
// This function returns an array which contains all connected devices
function getDevices(){
global $objMm1Protocol;
$intDevices = $objMm1Protocol->GetDeviceCount();
$arrDevices[0] = "No devices detected";
for( $i = 0; $i < $intDevices; $i++ ){
$arrDevices[$i] = $objMm1Protocol->GetDevice($i);
}
return $arrDevices;
}
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/mobile-messaging-component.