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

To send an SMS from PHP through a GSM modem, open the modem’s AT-command serial port, select SMS text mode with AT+CMGF=1 if the device supports it, then use AT+CMGS to submit the recipient and message. The important part is to wait for and parse each modem response: writing bytes successfully does not prove that the modem accepted the message or that the recipient received it.

What you need before sending an SMS

PHP runs on the host computer; the modem receives commands over an exposed serial interface, often presented as a USB serial port. A device marketed as a GSM modem may expose several interfaces, and not all of them accept AT commands. Check the modem’s documentation and identify the correct port for your operating system.

  • A cellular modem with SMS AT-command support, working SIM/account, and radio compatibility with your carrier and country.
  • A suitable connection: USB serial, or a UART connection with compatible voltage levels and wiring.
  • A PHP-side serial-port implementation that works with your operating system and installed PHP runtime. There is no single universally suitable PHP serial API established for every platform.
  • The modem manual’s serial settings, including baud rate, flow control, line endings, timeouts, and command syntax.

The 3GPP SMS command family is standardized, but modem firmware, interface setup, and supported options still vary. Consult the target device’s manual alongside the ETSI TS 27.005 standard.

Choose SMS text mode or PDU mode

Mode Command What it means
Text mode AT+CMGF=1 Usually the simpler choice for a basic send workflow, if the modem supports it. Character handling and message limits remain device-dependent.
PDU mode AT+CMGF=0 Requires the application to construct and encode the SMS protocol data unit. Use it when the device or application needs PDU-level control, and follow the modem documentation.

The command selects a format; it does not guarantee that a particular modem supports every encoding or message type in that format. Verify behavior on the actual device.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#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.

Send an SMS with the AT command sequence

  1. Connect to the AT port. Discover the modem’s command interface using the operating system and device documentation. Open it through a serial implementation compatible with your PHP runtime.
  2. Probe the modem. Send AT using the required line termination and wait for a response, commonly OK. If there is no response, resolve port and serial settings before continuing.
  3. Select text mode if appropriate. Send AT+CMGF=1 and read the complete response. Continue only if the modem accepts the command.
  4. Start the send operation. Send AT+CMGS="+15551234567", replacing the example with the destination number in the format expected by your modem and carrier. Wait for the modem’s message-entry prompt, commonly >.
  5. Submit the message body. Only after the prompt, write the message text, then send Ctrl+Z (ASCII 26) to tell the modem to submit it. Do not send Ctrl+Z as ordinary printable text.
  6. Read the final result. Wait for the modem’s completion response. A message reference followed by OK commonly indicates acceptance by the modem; an error response means the send attempt failed. Use the modem’s supported status-report features if you need delivery information.

Conceptually, the interaction is:

AT
                 → OK
AT+CMGF=1
        → OK
AT+CMGS="+15551234567"
 → >
Hello from PHP<Ctrl+Z> → +CMGS: <reference> ... OK

This is an illustration of the command exchange, not a drop-in PHP program: serial-port APIs differ across operating systems and PHP installations, and the exact responses and terminators depend on the modem. MikroTik’s RouterOS documentation likewise identifies AT+CMGS and AT+CMGF for sending, but its implementation-specific limitations should not be applied to other modems: RouterOS SMS documentation.

Read replies instead of assuming success

Build the PHP serial layer as a sequence of writes and response reads. A successful host-side write only means data was handed to the interface; the modem’s reply determines whether it accepted each command. Read until a complete response or a carefully chosen timeout, and distinguish the prompt from final results such as OK, ERROR, or extended SMS errors.

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

Do not treat a modem reference or OK as proof that a handset received the SMS. Network acceptance, delivery reports, and error detail depend on modem capabilities and configuration. For more than sending, TS 27.005 also defines commands including +CMGL (list), +CMGR (read), +CMGD (delete), +CPMS (storage), +CNMI (new-message indications), and +CSCA (service-centre address).

Troubleshoot common failures

Symptom What to check
No response to AT Confirm modem power, cable, selected interface, serial settings, and whether another application has the port open. Some devices expose multiple USB interfaces, with only one acting as the AT port.
Echoed or garbled characters Check baud rate, flow control, line termination, and echo behavior against the modem manual.
No prompt after AT+CMGS Read any error preceding the prompt. Verify SMS mode, destination syntax, SIM/account status, and whether the firmware supports the command.
Modem accepts the command but recipient gets nothing Inspect the final modem result; check network registration, signal, service plan, number format, service-centre configuration where applicable, and carrier/network SMS support. Acceptance is not delivery confirmation.
Unicode or long message behaves unexpectedly Check the modem’s character encoding, text-mode limits, and segmentation behavior. Test the exact message and encoding path; do not assume all modems handle concatenated or Unicode messages the same way.
Intermittent or corrupted commands Serialize access to the modem port. Avoid having multiple processes issue commands simultaneously; one operation can otherwise consume another’s response or interrupt its command sequence.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a modem interface that fits the host

A USB modem with a documented SMS AT-command port is often the most direct setup for a computer, provided its drivers, radio bands, and carrier support fit the intended location. A module exposing UART can also work, but may require an adapter and correct voltage, wiring, and port configuration. Neither connection type is universally preferable: choose based on documented AT support and compatibility with the host and network.

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.
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.
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

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.