Welcome to Infobip how to create your own SMS web application for beginners. We will help you step by step through the complexity of installing
SMS API from Infobip and SMS services. The manual includes 3 examples of the most important options for sending SMS messages and checking their status:
- Full featured text messages
- Logs sent messages
- Notify URL Delivery Reports
We will start with examples and presentations so that you can choose what is most interesting for you.
To follow this manual, write and test everything yourself, you need to prepare (and we do not mean pour a cup of coffee and turn off the light). In order to send messages, receive logs and reports on message delivery, you need to install the extension for your web server with
theURL php.
')
To work with this instruction, you can use the solution from the
AMP stack (wamp, xampp, etc.). This software stack for various operating systems consists of an Apache web server, a MySQL database and support for the PHP programming language. In any case, you must install the
phpcurl extension.
Note: to send SMS messages securely, these examples must be placed on HTTPS at startup (using TLS). To simplify the instructions, we used HTTP.Full featured text messages
The text messages page (
advancedSms.php ) contains a form
for sending messages . The submit button will send a request to the form
action attribute. In this example, she will send it to herself.

Build query
Before you start changing values, you must check that you have installed them correctly. In this example, we checked only the
“toInput” field
. You do not need to check them all, because the HTTP POST method will set everything automatically (if any of the input fields is empty, its value will be an empty string). If you are loading the page for the first time, keep in mind that none of these fields will be present. We are just two steps away from creating the whole page. After checking the fields, you must determine the
URL to send the request , as well as the
body of the request to be sent. The body of the POST request will be represented as a JSON string. The formation of the request body will be as follows:

In the example, the message is sent to only one recipient. If you want to send this message to multiple addresses, all you need to do is create another destination and add it to the list of recipients.
Since
“to” is the only required field, you need to check if it is filled before sending the request. If its filling is skipped, the user will receive a message about the empty field.

To send a request, we select
cURL .

In the code above, we used many variants to create a query, which are initialized by
curl_init () :
- CURLOPT_URL - set the URL using the endpoint method in it
- CURLOPT_HTTPHEADER - set the content type and request header
- CURLOPT_HTTPAUTH, CURLOPT_USERPWD - authorization type, username and password
- CURLOPT_POST - HTTP method used - POST
- CURLOPT_POSTFIELDS - pre-created XML or JSON structured string
- Here you can familiarize yourself with other sending options.
When you set all the parameters, you need to run a
curl_exec ($ ch) query. This method will give you the answer that you can get in JSON and which you can use in future analysis. After completing the request, you will receive information about the HTTP response code, which we will use later in this instruction -
curl_getinfo ($ ch, CURLINFO_HTTP_CODE) .
Response analysis
If everything went right and you received the HTTP response code (200 OK 201 CREATED, etc.), you can extract the necessary information from the response body and present it to the user. In our example, we decided to present: Message ID, To, SMS Count, Status Group, Status Group Name, Status ID, Status Name and Status Description, but you can choose what you need.
In the
foreach loop below, the response will be shown in one line for each message:


Logs sent messages
If you select this option, the
logs.php page
opens with an input form for
receiving logs of sent messages . The confirmation button will publish these fields to itself.
Build query
logs.php is the page where the logs of the sent messages will be presented. You must specify the
URL to send the request with it sent to the
GET HTTP method this time (CURLOPT_HTTPGET option set to TRUE):

After executing the request -
culr_exec ($ curl) , and receiving the HTTP response code, you can start analyzing the body depending on the required response code field, similar to what we did
in the chapter on full-featured text messages .
Response analysis
If everything went right and you received the HTTP response code (200 OK 201 CREATED, etc.), you can extract the necessary information from the response body and present it to the user. In our example, we chose:
Message ID, To, From, Text, Status, Group Name, Status Description and Sent At , but you can choose what you need, just as before:

The next
foreach loop will be compiled for each field of the log of sent messages and entered in one row with the corresponding columns in it. In this case, a foreach loop for each field is necessary, because we requested it for all message logs.
In exceptional cases, you can analyze the body of the request in the same way as we did in the method of sending messages:

Notify URL Delivery Reports
This function is slightly different from the previous two - the
dlrPush.php page
is not used to request data, it is waiting for it. When data is “pushed” onto this page, it can be analyzed and displayed to the user accordingly.
Note: Delivery reports are “pushed” from the full featured text message page by entering the URL of this page in the Notify URL field. In addition, the Notify ContentType field is filled in, with which the page determines which type of body you need to receive.Receive delivery reports

The code above shows that file_get_contents ('php: // input') is used to get the raw POST data as a string. The lines below show you how to check the data provided in XML or JSON, and how to extract the delivery reports. For XML, we analyze whether the response body string begins with, and if not, try decoding it without errors - the function is
isson () If all conditions are FALSE, the
$ result variable is left unset. This means that we have to tell the user that the delivery report has not been published on the callback server.
Results analysis
The analysis of delivery reports is very similar to the analysis of the response of
full-featured text messages and
logs of sent messages , except that we do not check the HTTP response code (because there is no answer at all). All we have to do is choose what information from the delivery report we want to show and write it on the page.