SMS or short messaging service is an integral part of any business’s communication with its customers. Be it promotional SMS or transactional SMS, 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.

Also Check: How to Send 1000 SMS at a Time Free Online

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); print_r($response); function httpPost($post){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,”http://URL/V2/http-api.php?”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); curl_close ($ch); return $output; }

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

Get in Touch With Our PHP Experts for a Free Consultation

Email To SMS

Sending an SMS via email using PHP is very simple. Just write phoneNumber@domainName.com, 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 5473543765@vtext.com 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:

include_once “class.curl.php”; include_once “class.sms.php”;

$smsapp=new sms(); $smsapp->setGateway(‘mTalkz’); account; // mTalkz code has been tested on different accounts to be stable. echo “Logging in … “; $smsapp->login(‘username for mTalkz’,’password’); echo “Sending SMS … “; $result=$smsapp->send(’10 digit mobile number’,’Your text message’); if($result) { echo “Message sent”;    //If you see this your message has been sent successfully!! } else { echo “Error encountered : “.$smsapp->getLastError(); }