With nearly everyone carrying a mobile phone, Short Message Service (SMS) is a powerful way to reach people wherever they are. Your PHP application can leverage this service, too. However, SMS is not like e-mail, which is free and open to anyone with an Internet connection. SMS messages are delivered through the telecoms' cellular networks, and so you must use an SMS gateway server to access the network.
- Skill level:
Things you need
- PHP installation with CURL support
Select an SMS gateway service to use. This gateway will forward your messages into the telecoms' cellular network. The gateway service will cost money, because the telecoms charge for SMS message delivery. Take a look at Ozeki or TM4B for examples. There are other services, too, such as the Google SMS gateway.
Sign up for the service and get the necessary login credentials.
Acquire and read the Application Programming Interface (API) for your chosen gateway. The manner in which you send your SMS message will vary according to the API. But there is a general pattern it follows regardless of which gateway you choose.
Set up your request variables. Create an array called "$sms". This array will contain all the request variables your SMS gateway needs to send a message. You will likely need to set "$sms['to']" for the message receiver, "$sms['from']" for the message sender and "$sms['message']" for the contents of the message. Check the API for other data that needs to be sent.
Use CURL to send your request. See the CURL documentation on the PHP website for details on how to use CURL. You will use "curl_setopt()" to set the URL of your SMS gateway and to encode your "$sms" variable. You will use "curl_exec()" to send your SMS message to the gateway.
Examine the response that "curl_exec()" returns. If the response is "false," then your SMS was not sent. There may be a network problem on your server. If there isn't, check the SMS gateway API again to make sure you're sending all the necessary information correctly. Some SMS gateways offer debugging tools. If yours does, take advantage of them at this point. If the response was "true," then your message was sent successfully.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for