How to Send SMS in PHP using Fast2SMS API

In this tutorial, I will explain how to send SMS in PHP using fast2sms API in a step-by-step process. SMS sending is a very important part of any kind of web application that provides instant information to users’ phone numbers to verify OTP and sending credentials etc. It is one of the most required features used by developers and can be integrated with the help of APIs provided by the SMS providers.

Fast2SMS is an SMS service provider that provides various SMS services such as bulk SMS, Quick SMS, DLT SMS, etc. Bulk SMS is used by companies, schools, and colleges, etc. In this tutorial, we will use the quick SMS service by using the quick SMS API in our application. In quick SMS, users will get SMS from random numeric numbers. After creating an account in Fast2SMS, Rs. 50 credited to the user account for free.

Also read, Integrate Instamojo payment gateway in PHP step by step

Prerequisite:- Any PHP version, XAMPP, or WAMP server.

Required steps to send SMS in PHP using FastSMS API

Step 1:- Create an account on the Fast2SMS website.

Step 2:- After creating the account, in the dashboard, navigate to the dev API at the left side of the dashboard and copy the API key for later use as shown below.

Step 3:- Just below the API key, go the API documentation and select the POST method from quick SMS API in PHP language as shown below.

Step 4:- Now create a folder in the root directory of your local server. In my case, the folder name is smsinphp.

Step 5:- Now, create an index.php file inside the folder you have just created as shown below


Step 6:- Now create a PHP action file send_sms.php separately that was mentioned in the index.php file as shown below.

Illustration of the above code:-

  • First of all, we will receive the form inputs with the help of PHP global variable $_POST and store.
  • Next, we will put the input fields in an array. The array index “route”=>”q” is used for sending quick SMS through quick SMS API that is available 24*7.
  • Now, we will put our API key as mentioned earlier in the CURLOPT_HTTPHEADER array as “authorization”.
  • Now, if you echo the response in the else condition of the last part of the above code then you can see the response as shown below

Use the above code snippet just for checking the response of the message.

Step 6:- Now open the browser and enter the URL as shown below.


Now, you can send the SMS as shown below

Conclusion:- I hope this tutorial will help you to understand the concept of SMS sending. If there is any doubt then please leave a comment below.




Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Distributed micro-services using Spring Cloud — Externalizing Configuration — Part 2

Maven as a Devops Tool

DeltaLake on EMR

Story of a beginner in API Testing…

How Titanium Backup is Widely Used and Easy to Backup Your Data

How to review the DacPac before it gets deployed through — Azure DevOps

Here, There, and Everywhere: Why DataStax Built a Serverless, Multi-Region DBaaS

Advanced Networking: privately NATting a whole VPC to and from the on-prem

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Hi, This is Biplab and I am web developer well versed in PHP and other open source technologies. I am here to share my experience with the community.

More from Medium

Google places autocomplete example using maps JavaScript API -

Best Chrome Extensions for Developers

Portfolio (Web Application Development) | 059849 | Nur Aleesa binti Mohamad Ali|

How to install Sass on Linux — Ubuntu 18.04 / 20.04