Welcome to the SMS Gateway Center Blog!

Explore professional advice and step-by-step guides alongside relevant case studies to boost your audience reach and interaction. Begin your search now and discover how SMS Gateway Center can strengthen your business communication system.

PHP Script to Retrieve Long code Incoming SMS Data from SMS Provider

2 Way SMS Services allows you to receive information from your users using SMS Services. When a user, sends an SMS to a Short code or Long code number, you can actually retrieve that data on you website. The following PHP script will simply help you understand how you can retrieve Long code Incoming SMS data from your SMS provider.

Availing Short code / Long code Services:

You need to first of all, avail Short code / Long code Services from SMS Service Provider. Signup and get your Short code number, for example: 12345. Once you are assigned with number, now you have to decide your keyword where your user can mention the keyword and send you the required information, for example: SGCSMS as your keyword. A user can send SMS from his mobile device to your assigned Shortcode number as shown below in the image screenshot.

Retrieve Long code Incoming SMS

Shortcode Incoming SMS – Retrieve Data on your Website:

Once you are up and done with your Short code SMS settings, now you want to retrieve that data from your Incoming SMS Provider on your website.

First thing First: When you ask your SMS provider that you want to retrieve Long code Incoming SMS data, they would ask you to set up a script where they can forward the data using HTTP request. So, you need to come up with a programming script to receive data on your website. Lets take a sample code how you can retrieve the information.

Programming your PHP Script:

Save the following file as incoming_sms.php

<?php
//If you are planning to insert this data in your database, then create a database connection file and include the file name as shown below.
//ofcourse uncomment the following if you have that file
//include('db_con.php');

//We send out various information such as circle, operator, etc.,
//2 important parameters are Recepient Phone Number and Message
//So you can just grab those 2 important parameters as shown below.
//If $_GET is not working then try $_REQUEST

$incoming_sms_no = $_GET['phonecode']; //Short code or Long Code number [OPTIONAL]
$incoming_sms_keyword = $_GET['keyword']; //Short code or Long Code Keyword such as MYCOMPANY [OPTIONAL]
$recepient_mobile = $_GET['phoneno'];
$recepient_message = $_GET['content'];
$recepient_circle = $_GET['location']; //Recepient's Circle or Location [OPTIONAL]
$recepient_operator = $_GET['carrier']; //Recepient's Operator Name such as Idea, Airtel [OPTIONAL]

//Now you can print all the received data or insert it in your database.
echo $incoming_sms_no;
echo "<br />";
echo $incoming_sms_keyword;
echo "<br />";
echo $recepient_mobile;
echo "<br />";
echo $recepient_message;
echo "<br />";
echo $recepient_circle;
echo "<br />";
echo $recepient_operator;
echo "<br />";

//OR
//If you are planning to capture in the database, then store the values to your database table

Once you save this file, now upload to your website’s server. If you are uploading to the root server, then your URL would be

https://mysite.com/incoming_sms.php

Before giving this URL to your SMS provider, first test yourself by calling the complete URL such as

https://mysite.com/incoming_sms.php?phonecode=12345&keyword=SGCSMS&phoneno=9930447726&content=please+call+back+as+am+interested+in+your+services&location=Mumbai&carrier=Idea

Once you are satisfied with the results, then go ahead.

You have to give the above PHP script URL to your SMS Provider to forward the data. Once they start forwarding Incoming SMS Data, you will receive Incoming SMS data on your website. If the forwarding works okay then your developer can further code to store those data in your database or write to a file on your server for your easy access.

SMS Gateway Center provides Long code Incoming SMS services in India, if you are looking for Long code SMS Services, contact us with your requirement. We will be happy to assist you with best service in the industry.

If you are looking for Long code SMS Services Script, we can also develop it for your website along with SMS services for retrieving Long code SMS Data on your website with user interface, then you can rely on SMS Gateway Center.

Looking for for SMS Developers API documentation? Go straight to Developer API Documentation.

Have we missed something in this tutorial, let us know in the comments using contact form.

Save this interesting page on your favorite Social Media

Blog Author

SMS Gateway Center Desk

SMS Gateway Center is one of the largest and leading SMS Provider in India. It is run by a large professional team to cater small companies to large corporate companies. SMS Gateway Center is associated with the best operators in India covering the entire states in India. SMS Gateway Center has been serving through its SMS Resellers in more than 20 states in India. To become our SMS Reseller, kindly contact us

Looking for the best business communication solutions, get in touch!