How to send SMS using PHP, send SMS using PHP with source code

In this tutorial, we will learn how to send SMS using PHP. There are many SMS API service providers like Twilio, Nexmo, MSG91, Text local that you can use to send SMS using the PHP programming language.

//requested parameters
$data =array(
'message'=>'Hello World!',
//Generate URL-encoded query string
$datastring= http_build_query($data);
//initialising the Curl library
$ch = curl_init('');
//Set an option for a cURL transfer
$result =curl_exec($ch);


true to do a regular HTTP POST. This POST is the normal application/x-www-form-urlencoded kind, most commonly used by HTML forms.


The full data to post in a HTTP “POST” operation. This parameter can either be passed as a urlencoded string like ‘para1=val1&para2=val2&…’ or as an array with the field name as key and field data as value. If value is an array, the Content-Type header will be set to multipart/form-data. Files can be sent using CURLFile, in which case value must be an array.


false to stop cURL from verifying the peer’s certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option.


true to return the transfer as a string of the return value of curl_exec() instead of outputting it directly.


Perform a cURL session


Close a cURL session

You can change the requested parameters as per your SMS API.

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top