需要帮助使用PHP的短信代码

时间:2015-04-10 06:54:05

标签: php curl sms sms-gateway

我需要使用PHP代码发送短信。我正在使用msg91.com服务发送短信。我尝试过使用它但无法发送短信。我正在使用WAMP服务器并且cURL扩展已启用。

任何人都可以帮我一些步骤或一些想法,我该怎么办?

请参阅this site

1 个答案:

答案 0 :(得分:0)

填写空白

有多少条消息?

<?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="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 any
if(curl_errno($ch))
{
    echo 'error:' . curl_error($ch);
}

curl_close($ch);

echo $output;
?>