Search code examples
smsgsm

Send SMS from Linux programmatically


I want to send SMS ideally using PHP in a Linux Environment. I have a GSM modem which I want to use to send SMS. Can anybody please tell me an easy way to send SMS from Linux using a USB GSM modem?

Thank you


Solution

  • Your GSM modem will almost certainly support AT commands - you can see some history of AT, or Hayes, commands here: https://en.wikipedia.org/wiki/Hayes_command_set

    The commands supported can vary from device to device but the simplest command sequence to send an SMS message is fairly standard - an example, showing the communication over the serial port, is:

    AT+CMGF=1.  [you send this]
    OK          [Modem responds]
    AT+CMGS="+31628870634".   [you send this]
    > Yourtextmessage.→.    [Modem responds with > and you send text followed by return at end]
    +CMGS: 198  [Modem responds after a few moments when message is sent]
    

    You should be able to find many more examples with a quick search including using PHP - e.g. (at the time of writing): https://gonzalo123.com/2011/03/21/howto-sendread-smss-using-a-gsm-modem-at-commands-and-php/

    Its worth being aware that different modems may work differently - you will need to experiment to ensure you have a relabel solution.