Press "Enter" to skip to content

How to Send SMS using PHP Program (full code sample included)

Are you looking how to send message to mobile using php code? Are you searching for how to send sms using php source code?

How to send sms with php code from localhost

<?php

//Your authentication key
$authKey = "YourAuthKey";

//Multiple mobiles numbers separated by comma
$mobileNumber = "9999999";

//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "102234";

//Your message to send, Add URL encoding here.
$message = urlencode("Test message");

//Define route 
$route = "default";
//Prepare you post parameters
$postData = array(
    'authkey' => $authKey,
    'mobiles' => $mobileNumber,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route
);

//API URL
$url="http://api.msg91.com/api/sendhttp.php";

// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
    //,CURLOPT_FOLLOWLOCATION => true
));


//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);


//get response
$output = curl_exec($ch);

//Print error if any
if(curl_errno($ch))
{
    echo 'error:' . curl_error($ch);
}

curl_close($ch);

echo $output;
?>
0Shares

You May Missed it !

Difference Between Percentage and Percentile Difference Between Percentage and Percentile - Percentages and percentiles are important metrics that go a long…
Home Lifestyle Trends for 2021 Top New Home Lifestyle Trends for 2021 - How are homes in the 2020s different? For starters, just…
Cost-Effective Ideas To Further Your Education Without Attending College Cost-Effective Ideas To Further Your Education Without Attending College - Are you a recent high school graduate with no clear…
5 Ways To Get Yourself Out Of Debt Before Turning To Bankruptcy 5 Ways To Get Yourself Out Of Debt Before Turning To Bankruptcy - 80% of Americans have some form of debt. When we…
What Workforces Look Like During Recovery in 2021 What Workforces Look Like During Recovery in 2021 - The worst part of covid’s impact on the economy is…
Educational Netflix Shows to Stream in Your Classroom Educational Netflix Shows to Stream in Your Classroom - When learning is fun, the lessons are retained better in…
Personal Loan How to Pay for Your Dream Wedding - One of the most significant expenses you and your fiancé…
Techno Mobile Tecno Mobile Launched AI-Powered Smartphone in India 2021 - When it comes to smartphones getting the complete package is…