sms gateway integration in php

home Home location_on Geo Tools construction Web Tools question_answer Chat With Us CALL US Tutorials expand_more integration_instructions How To data_object Scripts text_snippet Snippets preview Demos developer_mode Web Development Service search Search tutorials HOME PHP SMS GATEWAY INTEGRATION IN PHP SMS Gateway Integration in PHP By: https://speedsms.in/ | In: PHP | Last Updated: Mar 6, 2023…

Category:

Description

home
Home
location_on
Geo Tools
construction
Web Tools
question_answer Chat With Us

CALL US


Tutorials expand_more
integration_instructions How To
data_object Scripts
text_snippet Snippets
preview Demos
developer_mode Web Development Service
search
Search tutorials

HOME
PHP
SMS GATEWAY INTEGRATION IN PHP
SMS Gateway Integration in PHP
By: https://speedsms.in/ | In: PHP | Last Updated: Mar 6, 2023
Share

These days SMS feature is used for various purposes in the web application. For example user authentication, OTP verification, and sending notifications to users. To send SMS from a PHP script you need to select the best SMS gateway provider that is suitable for your requirement. Once the SMS gateway and plan selection are completed, now it’s time to integrate SMS gateway in PHP.

In this tutorial, we will show you how to integrate SMS gateway API in PHP. The SMS gateway integration process is very simple and less time is required. Using our example code you can easily send SMS from your website using SMS gateway API and PHP.

Usually, the SMS provider provides 3 types of plans, One-way messages, Two-way messages, and Both-ways messages. One-way messaging allows you to send SMS to the customers, but Two-way messaging not only send SMS but also receive reply from the customer.

Generally, an SMS gateway provides a callback URL for passing some parameters, like API Key, sender number, receiver number, message content, etc. The parameters can differ for the different SMS gateway, based on that you need to change or add parameters in the following script.

SMS Gateway API with GET Request:

// Request parameters array
$requestParams = array(
‘apiKey’ => ‘YOUR_API_KEY’,
‘senderID’ => ‘CODEXW’,
‘receipientno’ => ‘XXXXXXXXXXXX’,
‘message’ => ‘Insert sms content’
);

// Append parameters to API URL
$apiURL = “https://api.example.com/sendsms?”;
foreach($requestParams as $key => $val){
$apiURL .= $key.’=’.urlencode($val).’&’;
}
$apiURL = rtrim($apiURL, “&”);

// Send the GET request with cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

// Process API response here
echo $response;
SMS Gateway API with POST Request:

// API URL
$apiURL = “https://api.example.com/sendsms”;

// Request parameters array
$requestParams = array(
‘apiKey’ => ‘YOUR_API_KEY’,
‘senderID’ => ‘CODEXW’,
‘receipientno’ => ‘XXXXXXXXXXXX’,
‘message’ => ‘Insert sms content’
);

// Send the POST request with cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestParams);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

// Process API response here
echo $response;
Note that: The above SMS Gateway Integration script uses the cURL method, make sure that the cURL is enabled in PHP.

api
php
sms gateway
Do you want to get implementation help, or enhance the functionality of this script? Click here to Submit Service Request

Previous
arrow_back
Download File from Database in CodeIgniter
Next
CodeIgniter File Upload Validation
arrow_forward
RELATED TUTORIALS
upload-import-excel-file-data-into-mysql-database-using-php-https://speedsms.in/
Read More
Import Excel File Data into MySQL Database using PHP
php-large-event-calendar-add-events-to-database-jquery-ajax-mysql-https://speedsms.in/
Read More
PHP Event Calendar – Add Events to Calendar using jQuery and Ajax
upload-video-to-youtube-with-data-api-using-php-https://speedsms.in/
Read More
Upload Video to YouTube using PHP
4 COMMENTS
Tejas Said…
Hello,
The script is good enough. But If I want to send dynamic messages to any dynamic number after any form submission where I have added/integrated sms api key.

Your code contains ‘receipientno’ => ‘XXXXXXXXXX’, so here I want to call dynamic php contact number id, so how should I call there in your script??

January 22, 2018 at 10:09 AM
Himanshu Goel Said…
Thanks a lot, though I required some changes to be done, but it worked fine…

November 15, 2017 at 2:01 PM
Rizwan Khan A Said…
nice

July 26, 2017 at 12:32 PM
Bhushan Said…
Thank You for this valuable information and it is very crisp and clear.
I am using this and it is working fine.

I am facing one issue, I think it is because of SMS service provider. The response is taking ~10 Secs.
I am using above code from my controller when business flow is valid.

Do you see any possibility that we invoke above request but let’s not wait for response. I mean send SMS request to Service Provider and continue with further steps. (At least in this scenario, I am not interested to know whether my SMS request is success or not but I want my business flow should be executed little faster and should not hinder because of delay from SMS service provider)

February 16, 2017 at 10:24 AM
LEAVE A REPLY
Comment*
Your Name*
Your Email*
Your Website

TRENDING TUTORIALS
Convert HTML to PDF using JavaScript
Upload and Store Image File in Database using PHP and MySQL
Multi-select Dropdown List with Checkbox using jQuery
Login with Google Account using PHP
Store and Retrieve Image from MySQL Database using PHP
Login with Facebook using PHP
Dynamic Dependent Select Box Dropdown using jQuery, Ajax and PHP
Add Remove Input Fields Dynamically using jQuery
TOPICSall topics
PHP
CodeIgniter
WordPress
JavaScript
GoogleMap
HTML&CSS
Web Development
Drupal
Bootstrap
CakePHP
Laravel
PayPal

LATEST HOW TO GUIDES
How to Add Full Screen Control to OpenStreetMap using JavaScript
How to Customize the OpenStreetMap Marker Icon using JavaScript
How to JOIN Multiple Tables in DataTables Server-side Processing using PHP
How to get file content from URL in PHP
How to avoid javascript:void(0) and use an alternative in empty href links?

CALL US


https://speedsms.in/ is the most popular Programming & Web Development website aiming to provide the best online resources for web application developers and designers.

https://speedsms.in/ Android App
ABOUT US
radio_button_checked
About https://speedsms.in/
radio_button_checked
Write For Us
CONTACT
radio_button_checked
Contact Us
radio_button_checked
Advertise
TERMS
radio_button_checked
Terms & Conditions
radio_button_checked
Privacy Policy
EXTRA LINKS
radio_button_checked
Q&A Community
radio_button_checked
Online Tools
Copyright © 2024 https://speedsms.in/. All rights reserved.

gavel Terms & Condition
verified_user Privacy Policy
keyboard_double_arrow_up