October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Send SMS from PHP Through a GSM Modem

PHP sends AT commands over a serial connection; the GSM modem and SIM handle the cellular SMS. Here is the command sequence and how to troubleshoot common failures.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PHP can send SMS through a GSM modem by opening its serial port and issuing AT commands. In the common text-mode sequence, the modem must answer AT, switch to SMS text mode with AT+CMGF=1, accept the recipient with AT+CMGS, and receive the message followed by Ctrl+Z. The modem—not PHP—handles the cellular transmission. The Windows COM-port example discussed in the SitePoint Forums thread is legacy code, so port access and serial configuration need adapting to the current machine and modem.

What PHP and the GSM modem each do

PHP acts as a serial client: it sends commands and data to a modem connected to the computer. The modem uses its SIM and cellular connection to submit the SMS. This is different from sending through an SMS API over the internet; the local approach depends on attached hardware, a working SIM, network availability, and operating-system access to the modem.

As an Amazon Associate I earn from qualifying purchases.

The SitePoint example was written for a Windows COM port, specifically COM6, and uses the Windows MODE command. Its author’s goal was a form that could send messages to multiple recipients. Treat its code as a description of the command flow, not as a drop-in solution for a current PHP or Windows installation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the modem and serial connection first

Before debugging PHP message logic, establish which serial interface the modem exposes and whether the operating system allows the PHP process to open it. COM-port naming, baud rate, drivers, and access permissions vary by device and operating system. The legacy example configures a Windows port using MODE {$port}: BAUD={$baud} PARITY=N DATA=8 STOP=1, then opens it with fopen($this->port . ':', 'r+'); neither that setup nor the device settings should be assumed to work unchanged on another system.

#1 Best Overall
EC Buying SIM800C USB to GSM Module Quad-Band GSM/GPRS Wireless Module Integrated USB to Serial Chip GSM/GPRS 850/900/1800/1900MHz Support 2G/3G/4G Micro SIM Card/Bluetooth/SMS Data Transmission
  • ◇Introduction: USB to GSM is a four-frequency GSM/GPRS module, its stable performance, and can meet a variety of customer needs. Integrated USB to serial port chip, directly plug in the computer can be debugging. The operating frequency of SIM800C is GSM/GPRS 850/900/1800/1900mhz, which can be used worldwide. It can realize the transmission of voice, SMS messages, and data information with low power consumption, and can be suitable for various compact product design requirements.
  • ◇ On-board original SIM800C GSM/GPRS module; On-board CH340T USB to serial port chip, simple driver installation and high compatibility; self-elastic SIM card slot design, can use 2G/3G/4G Micro SIM and Nano card;
  • ◇The USB to GSM module will automatically start up and connect to the network when it is powered on. It does not need to control the startup with buttons, which saves the troublesome startup process;
  • ◇Support SMS sending and receiving, provide management software; provide reference host computer source code (c#, vb) supporting materials and instructions for use; support GPRS data transmission under 2G network, which can be used in mobile meter reading and other occasions;
  • ◇Support Bluetooth data transmission, IEEE802.15 bluetooth standard, 2.4GHz working frequency band; support adaptive baud rate; with working indicator, no network, no SIM card or when the SIM card is inserted backward, the LED light flashes quickly at 1-second intervals, normal Blinks once every 3 seconds when connected to the network.
  • Confirm the modem is connected, recognized by the operating system, and associated with the serial port you intend to use.
  • Use the baud rate and other serial settings required by that modem; the example’s settings are not universal.
  • Ensure the account running PHP can access the device and, for the sample Windows approach, can invoke the system mode command.
  • Confirm the SIM, cellular service, and carrier compatibility are suitable for SMS. Hardware interface, cellular bands, drivers, and carrier support are device- and region-dependent.

The AT-command sequence for a text SMS

  1. Open the serial port and test communication. Send ATr and wait for OK. If the modem does not respond, fix the port, permissions, driver, or serial settings before attempting SMS commands.
  2. Select text mode. Send AT+CMGF=1r. This tells the modem to use SMS text mode.
  3. Set or verify the service-center address. The Stack Overflow discussion of this flow notes that the SMS service-center address may need to be set with AT+CSCA. A missing or incorrect setting can prevent delivery even if the later command sequence is correct. The required address depends on the SIM or carrier; do not copy an arbitrary value.
  4. Start a message. Send AT+CMGS="destination-number"r, replacing the quoted value with the recipient’s number in the format expected by the modem and network. Wait for the modem’s > prompt before writing message content.
  5. Send the body and submit it. Write the message text, then send chr(26) (Ctrl+Z). Wait for a modem result. The legacy sample allows up to 180 seconds for an OK response and treats a +CMS ERROR or timeout as failure.

The related Stack Overflow answer confirms the central text-mode sequence—AT+CMGF=1, AT+CMGS, message text, and Ctrl+Z—and calls out AT+CSCA as a preliminary service-center step. A modem’s responses and supported command behavior can vary, so record what the actual device returns rather than assuming every successful-looking write means delivery.

Why the old PHP example needs adaptation

The forum class sends ATr, waits up to five seconds for OK, selects text mode, and then processes each recipient by waiting for the prompt and final result. Those waits illustrate an important point: serial communication is a request-and-response exchange. Writing bytes to a port is not the same as confirming that the modem accepted a command or submitted a message.

Rank #2
OSTENT GSM Modem with Wavecom Q2303A Module USB Interface AT Commands SMS
  • Industrial-Grade GSM Modem
  • Based on Wavecom Q2303A Module
  • USB Port Interface
  • Control via AT Commands
  • Support Dual Frequencies: GSM 900/1800MHz

A related question explicitly labels the class Windows-only and reports testing on Windows XP with PHP 5.2.6. That vintage matters: modern PHP versions, Windows configurations, and non-Windows operating systems may not support the same port-opening approach. See the related Stack Overflow question for the stated legacy context. Use a serial-port library or platform-specific interface appropriate to the deployment environment if the old MODE and fopen() technique does not work.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose “Did not receive response from modem”

If the application times out waiting for a response, locate the earliest step that fails. A timeout while waiting for the initial OK points to serial communication, not message content; a failure after AT+CMGS may instead involve command syntax, modem state, SIM or network service, or the service-center configuration.

Rank #3
WDINLY 4G LTE USB Modem Dongle Router with WiFi Hotspot, High Speed 4G Modem Wireless Internet WiFi Hotspot Router Unlocked Portable Support FDD:B2/B4/B5/B12/B17 for PC Desktop Laptop Tablet
  • 🏡【High-speed 4G LTE USB Modem Dongle】4g lte wifi modem router has super signal receiving capability and efficient data transmission. Our 4g usb sim card modem mobile wifi hotspot adopts IEEE 802.11b/g/n wireless transmission standard and has a wireless speed of up to 150Mbps, download speed 100Mbps, upload speed up to 50Mbps. Large coverage area, 10 meters long-distance transmission. The wireless internet router extendable is suitable for AT&T, T-Mobile, Mint Mobile. portable wifi 4g sim card wifi modem
  • 🏡【Plug and Play】The 4g wifi modem usb router is driver-free and don't need to install software, power-connected via USB, you can provide a network to the computer, which makes it convenient to use. You can also connect your mobile phone to the usb cellular modem portable wifi for use. 4g lte dongle We recommend that you use the 4g usb modem for short distances indoors. usb fax modem modem router combo hotspot device portable wifi hotspot for travel
  • 🏡【Small Portable 4G Dongle With Sim Card Slot】usb 4g lte modem You can take this 4g wifi router portable everywhere where you want, and adjust the angle of damping metal shaft according to your own usage habits and signal strength. The 4g lte wifi router can be able to connect with tablet ,laptop, notebook and various types of WiFi devices. WDINLY 4g lte usb modem dongle router is suitable for travel, outdoor working, business meeting and outdoor barbecue. If you want a PDF manual for using this 4g lte modem mobile hotspot, you can download it from the "Product guides and documents" section of the product detail page. 4g lte router with sim card slot
  • 🏡【Compatible 4G Wifi Router Modem】The hotspot wifi portable for car can access to 10 devices. This 4g wifi router with sim card slot can be connected and used if there are wifi-enabled devices, such as mobile phones, smart robots, iPads, smart speakers, cameras, TVs, computers, etc. usb lte modem The USB WiFi modem device is widely compatible for Windows XP (SP3), Windows Vista (SP1), Windows7 or Windows8/10, and Macs with OS x v10.5.7, OS X Lion V10.7.3 or later. WiFi Standard: 802.11 b/g/n devices. 4g lte usb dongle unlocked
  • 🏡【Why Choose This Mobile Hotspot Device】4g portable usb modem You can change or hide the internet password of your portable wifi hotspot no contract, you can build a wifi environment that won't be easily cracked by others. Its built-in antenna has multi-wide-angle coverage to accurately accept amplified signals. portable internet hotspot The signal of portable wifi for car can intelligently track the location of wireless terminals, such as mobile phones, computers, iPads, and TVs, enhance the unknown WiFi signal strength of each device.4g lte usb portable router
  • No response to AT: Check the selected COM port or serial device, driver, process permissions, baud rate, and whether another application already has the port open.
  • No OK after text-mode selection: Check that the modem accepts AT+CMGF=1 and that the command terminator and serial settings match the device.
  • No > prompt after AT+CMGS: Confirm the recipient syntax, modem readiness, and that the command was sent in the expected state. Do not write the message body until the prompt arrives.
  • +CMS ERROR or no final confirmation: Capture the exact modem response, check SIM/network availability and the service-center address, and distinguish a modem error from a timeout in PHP’s read loop.
  • Modem accepts the message but it is not received: A command acknowledgement alone is not proof of end-to-end delivery. Check carrier/SIM service and any delivery-report facilities the device supports.

Log the command stage, timestamps, and raw modem response while avoiding unnecessary retention of message content or personal data. This makes it possible to tell whether a failure occurred before submission, at modem acceptance, or after the message left the device.

Make a multi-recipient form safer

The SitePoint sample includes a browser form that can add or delete recipient rows, but a dynamic form is not a sending safeguard. Before using a similar interface beyond a local demonstration, validate destinations, protect the form, and control how messages are queued and retried.

Rank #4
4G LTE USB Modem, Portable Router Mobile Internet Devices for Home Travel Office, Mobile Hotspot Network Router with SIM Card Slot, Support 10 Devices
  • Plug and play: 4G mobile is plug and play, enjoy 4G internet, convenient USB power supply method, connect power device, insert SIM card, use SIM card data to surf the Internet anytime, anywhere.
  • Multiple : router adopts multiple design, more secure, WPA/WPA2 encryption, effectively avoid internet squatting, support data control.
  • Support Multiple Users: USB portable supports multiple terminals to access the Internet at the same time, and supports 10 devices, such as mobile phones,laptops, computers, smart TVs and other devices.
  • USB Powered: Portable supports multiple 4G networks, sharing up to 10 users, powered by devices with USB ports, such as mobile phone chargers, car chargers, power banks, etc.
  • High Speed Stable: 4G USB portable provides fast and stable high speed Internet access, high speed 4G internet, stable , feel the wonderful internet life, and fast Internet access.
  • Validate and normalize phone numbers to an international format appropriate to the target recipients.
  • Require authentication and protect form submissions against cross-site request forgery.
  • Rate-limit sends and enforce sensible recipient and message limits.
  • Prevent duplicate submissions, especially when the browser retries or a user refreshes after a delay.
  • Queue work rather than holding a web request open through long modem waits; record outcomes and make retries deliberate to avoid duplicate SMS.
  • Keep an auditable log of modem responses and send status while limiting exposure of phone numbers and message content.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a local modem is the right fit

A GSM modem can suit a deployment where local hardware and a SIM are available and the application can maintain a reliable serial connection. It also makes the application responsible for hardware setup, operating-system integration, carrier/SIM dependence, modem monitoring, throughput constraints, and failure recovery. A hosted SMS gateway/API avoids a local serial device but introduces a service dependency and its own costs and delivery-report behavior. The cited discussions establish the local modem command flow; they do not provide current prices, throughput figures, or delivery benchmarks for comparing the approaches.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
4G LTE USB Modem,Mobile Internet Devices SIM Card Slot,High Speed Portable Travel Hotspot Mini Router,Up to 10 Users,Black
  • Easy Connection: This 4G LTE router only needs to be inserted with SIM card to search and connect, automatically turn on high speed 4G.
  • Up to 10 Users: This 4G router supports up to 10 users, suitable for phone, laptop, tablet, PC and TV, etc.
  • High Safety: This mobile router with multiple adopts WPA/WPA2 encryption to provide security, support data control.
  • Portable Size: This SIM dongle features in small and portable size can provide fast and stable .
  • Plug and Play: This 4G USB modem can be powered by devices with USB port, such as phone charger, car charger and power bank.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.