首页 > 代码库 > 发送信息给用户
发送信息给用户
function send_sms($mobile, $msg)
{
$authKey = "XXXXXXXXXXX";
date_default_timezone_set("Asia/Kolkata");
$date = strftime("%Y-%m-%d %H:%M:%S"); //Multiple mobiles numbers separated by comma
$mobileNumber = $mobile;
//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "IKOONK";
//Your message to send, Add URL encoding here.
$message = urlencode($msg);
//Define route
$route = "template"; //Prepare you post parameters
$postData = http://www.mamicode.com/array(
‘authkey‘ => $authKey,
‘mobiles‘ => $mobileNumber,
‘message‘ => $message,
‘sender‘ => $senderId,
‘route‘ => $route
);
//API URL
$url = "https://control.msg91.com/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 anyif(curl_errno($ch))
{
echo ‘error:‘ . curl_error($ch);
}
curl_close($ch);
}
发送信息给用户