SMS or short messaging service is an integral part of any business’s communication with its customers. Be it promotional or transactional, SMS creates direct contact with your customers and gives them critical and real-time information, such as an OTP for login, or a coupon code that expires in a week. Automating these messages makes sense as the marketing team can focus on curating messages rather than sending them. A host of SMS automation solutions is available, but the most versatile and robust is using a PHP software.
What is PHP?
PHP was released back in 1994 by Rasmus Lerdorf, a Danish Canadian programmer. PHP, an acronym for Hypertext Preprocessor, is a general-purpose scripting language especially suited to web development. PHP is so versatile and robust that companies like Facebook and WordPress use it as their website’s backbone! It is also intuitive and easy enough for beginners to start with backend development. Thus, you can surely use it to automate your SMS deliveries. Let’s get started.
How to Integrate a SMS API in PHP?
Step 1: Download PHP
Head over to https://www.php.net/ and download the latest PHP stable software package for your device. Click on the download page and then click windows download. Once there you have a few options, click on a zip download and extract the zip on a folder. The unzipped folder will contain a windows installer Exe file, run that as an administrator, and click install.
Note: It is imperative to match computer architecture to the software architecture. For example, x86 software of PHP will run only on x86 windows machines.
Note: For other systems and troubleshooting, please click on this link https://www.php.net/manual/en/install.php
Step 2: Select an SMS API provider
SMS API providers are organisations that have created a development tool on their servers to make use of PHP and automate message deliveries. There are a host of options for you ranging from http://freesmsapi.com, which provides free SMS API services to mTalkz that has a more sophisticated API, more features and unparalleled customer support. Head over to SMS API for developer for more information.
Once you have narrowed down and selected your SMS API provider, it’s now time to code and automate message deliveries.
Step 3: PHP Code to Integrate SMS API
$postData = ‘apikey=XXXXXXXXXXXXXXXX&senderid=XXXXXX&number=
XXXXXXXXXXX,XXXXXXXXXXX&message=Test Post API&format=json’;
$response = httpPOST($postData);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
There is no one right way to code for such a scenario. You might find variations of the same code or a different code entirely, and all are correct. This is just one way to send SMS through SMS API using PHP.
Here in this code, we are going to do three main things.
- Create a message on a server and send it to an SMS Gateway via Email.
- The SMS Gateway converts the text in the Email to SMS
- This message is relayed to a short message service centre, whose servers send the message to individual numbers
Email To SMS
Sending an SMS via email using PHP is very simple. Just write [email protected], where the phone number is the target number, and the domain name is the network for the SMS Gateway.
For example, To send an SMS through PHP to XYZ, you could add [email protected] to any email client, type a message, and hit send. This will send a text message to phone number +1 (547) 354-3765 on the Verizon Wireless Network.
Here is a full PHP code for the same:
echo “Logging in … “;
echo “Sending SMS … “;
How to Send SMS using PHP Program (full code sample included)?
How to send sms from localhost to mobile?
how to send message to mobile using php code?
how to send sms from website using php?
how to send otp sms using codeigniter?
how to send otp sms using php free?
how to send message in android programmatically?