Sending SMS from PHP
An engine sending short messages directly from a PHP script is very useful for
webmasters. Headwind SMS Suite may be used to send SMS from the website in two manners.
The first solution is to use a separate SMS server which periodically
asks a web server about pending messages. However, if you have a Windows-based web server,
you may implement the SMS engine directly in PHP! All you need is Headwind GSM Modem Driver and
the support of COM/.NET in PHP (the latter is included
in a latest version of the PHP package for Windows by default).
Step-by-step guide
The whole description of the SMS API provided by Headwind may be found
in the SMS API guide. In this article, we describe what you need to
send your first SMS from a personal web server in a step-by-step manner.
- Download and install Headwind GSM Modem Driver. Setup the GSM modem
in accordance with the user manual.
- Setup the application access mode for Headwind GSM Modem Driver API objects using
the dcomcnfg utility (here is some more info about using
dcomcnfg with Headwind GSM Modem Driver):
- Run dcomcnfg.exe (Start->Run->dcomcnfg.exe)
- Open the item Component Services->Computers->My Computer->DCOM setup->HeadwindGSM,
right-click the item and select 'Properties'
- Open the 'Identity' tab and select 'Current user'.
- Click 'Apply' to change the access mode.
Allowing web scripts to start applications from other user identity may potentially
increase the host vulnerability. If you have a public web server, please consult your
system administrator on the security issues!
- Download and install Apache and PHP 5 for Windows. We recommend to use WAMP server
(Windows Apache, Mysql, PHP): http://www.wampserver.com.
Check that it works properly by typing http://localhost/index.php in your web browser.
- Allow to interact web pages using Headwind GSM Modem Driver with desktop:
- Open the list of Windows services (Start -> Control Panel -> Administrative tools -> Services)
- Find the service 'wampapache', click it by right mouse button and select 'Properties'
- Select the tab 'Log On', select 'System account' and
set the flag 'Allow to interact with desktop'
- Click OK, then close WAMP server and start it again
- Put a sample PHP script into your www directory.
<?php
// Get address and message
$addr = $_GET['addr'];
$body = $_GET['body'];
// Open Headwind GSM Modem Driver
$hgsmdrv = new COM("HeadwindGSM.SMSDriver") or die("Unable to open Headwind GSM Modem Driver");
// Connect to GSM modem
$hgsmdrv->Connect();
// Create message
$sms = new COM("HeadwindGSM.SMSMessage") or die("Unable to create SMS message");
$sms->To = $addr;
$sms->Body = $body;
// Send message
$sms->Send();
//free the objects
$hgsmdrv = null;
$sms = null;
echo "Message '$body' has been sent to '$addr'";
?>
Save this code in your www directory as sms.php, then type in the web browser the following URL
(replace '12345678' to your mobile phone number):
http://localhost/sms.php?addr=12345678&body=Hello+World
The web server must open Headwind GSM Modem Driver and send an SMS to you.
|