1、使用curl函數(shù)發(fā)送短信:
使用curl函數(shù)發(fā)送短信,需要先安裝curl擴(kuò)展,然后使用curl函數(shù)發(fā)送短信,代碼如下:
<?php
$url = 'http://www.example.com/sms.php';
$data = array('phone' => '1234567890', 'message' => 'Hello World!');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
2、使用fsockopen函數(shù)發(fā)送短信:
使用fsockopen函數(shù)發(fā)送短信,代碼如下:
<?php
$url = 'http://www.example.com/sms.php';
$data = array('phone' => '1234567890', 'message' => 'Hello World!');
$postdata = http_build_query($data);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
echo $result;
?>