6
votes

I am trying to execute AT commands from PHP.

I tried exec() and shell_exec()

Please don't suggest third party SMS gateway my client doesn't want to disclose his private information and wants to send SMS from his own server.

I have a GSM modem attach to a serial port which I can access through "putty" like in fig putty screen 1

And I can enter AT commands to send SMS like in fig below. enter image description here

I want to run those AT commands through PHP.

2
have you tried plink.exe?Gerald Schneider
Can you telnet into the GSM modem? If so you could try to use fsockopen from PHP. php.net/manual/en/function.fsockopen.php And then use fwrite to write to the socket. php.net/manual/en/function.fwrite.phpn0tiz
@GeraldSchneider yes I guess here is url of what i am using chiark.greenend.org.uk/~sgtatham/putty/download.html but I want to execute AT commands through PHP, commands on black screen on second figMilind More
According to this 10 year old comment on the php manual you can just write to the com port with fopen.Gerald Schneider
WOW ! 10 year old comment, I will try that !Milind More

2 Answers

13
votes

Hi I am sending sms using php class on windows 8 by this php code.

require "php_serial.class.php";
$serial = new phpSerial;
$serial->deviceSet("COM4");
$serial->confBaudRate(115200);

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("AT+CMGF=1\n\r"); 
$serial->sendMessage("AT+cmgs=\"+92234444444\"\n\r");
$serial->sendMessage("sms text\n\r");
$serial->sendMessage(chr(26));

//wait for modem to send message
sleep(7);
$read=$serial->readPort();
$serial->deviceClose();

PHP SERIAL class Link

2
votes

You just need a RS232 communication class such as this one http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html

Alternatively you can also use fopen()

exec('mode COM1: baud=115200 data=8 stop=1 parity=n xon=on');
$fd = fopen('COM1:', O_RDWR);
fwrite($fd,chr(0).chr(1));
fclose($fd);