1. MSG91 SMS For INDIA
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.msg91.com/api/v5/flow/",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n \"flow_id\": \"your_flow_id\",\n \"mobiles\": \"your_mobile_number_with_country_code\",\n \"link\": \"your_message_attached_in_one_API_in_MSG91"\n}",
CURLOPT_HTTPHEADER => [
"authkey: your_auth_key",
"content-type: application/JSON"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}This code uses cURL to send an HTTP POST request to the MSG91 API to trigger a flow for sending an SMS message to a specified mobile number.
Here’s what the code does:
- Initializes a cURL session using
curl_init(). - Sets various options for the cURL session using
curl_setopt_array(), including the API endpoint URL, request method (POST), request body (including the flow ID, mobile number, and message to be sent), and request headers (including the authentication key and content type). - Executes the cURL session using
curl_exec()and stores the response. - Checks for any cURL errors using
curl_error(). - If there are no errors, it outputs the response using
echo.
Note that the code contains placeholders for various values (e.g., your_auth_key, your_mobile_number_with_country_code, your_flow_id, your_message_attached_in_one_API_in_MSG91) that need to be replaced with actual values specific to your MSG91 account and message details in order for the code to work.
2. Aakash-SMS For Nepal
$args = http_build_query(array(
'auth_token'=> 'your_auth_token',
'to' => 'your_phone_number',
'text' => 'your-message'
));
$url = "https://sms.aakashsms.com/sms/v3/send/";
# Make the call using API.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1); ///
curl_setopt($ch, CURLOPT_POSTFIELDS,$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Response
$response = curl_exec($ch);
curl_close($ch); This code is using the cURL library to send an HTTP POST request to the SMS API provided by the website sms.aakashsms.com.
It first builds a query string using the http_build_query() function, which encodes the parameters as a URL-encoded string.
The curl_setopt() function is then used to set options for the cURL session. Here, it sets the URL to the SMS API endpoint, specifies that it’s a POST request, sets the request body to the query string, and sets the CURLOPT_RETURNTRANSFER option to true, which returns the response as a string.
Finally, the curl_exec() function is called to execute the request and store the response, and curl_close() is called to close the cURL session.
Note that in the provided code, the line curl_setopt($ch, CURLOPT_POSTFIELDS,$args); is commented out, so the $args variable is not actually being sent as the request body.





