我想使用数据库表中找到的数字发送短信。我尝试了包含功能,但邮件未发送到号码。没有错误显示。
<?php
//connect to database
$con = mysqli_connect('127.0.0.1','root','');
//select database
mysqli_select_db($con, 'appointment');
if($_POST['accept'])
{
$sql = "UPDATE service SET remarks = 'Accepted' WHERE ID=$_POST[id]";
include"sms.php";
}
else if($_POST['reject'])
{
$sql = "UPDATE service SET remarks = 'Rejected' WHERE ID=$_POST[id]";
}
//Execute Query
if(mysqli_query($con,$sql))
header("refresh:1; url=app.php");
else
echo "Unsuccessful";
?>
这是我的sms.php的代码
<?php
$phone= "SELECT contact FROM service WHERE ID=$_POST[id]";
$message= "You're Appointment is Accepted";
send_sms($phone,$message);
function send_sms($phone, $message) {
$ch = curl_init();
$parameters = array(
'apikey' => '*****************', //Your API KEY
'number' => $phone,
'message' => $message,
'sendername' => 'SEMAPHORE'
);
curl_setopt( $ch, CURLOPT_URL,'http://api.semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );
//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );
// Receive response from server
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close ($ch);
//Show the server response
echo "Message Successfully Delivered";
}
?>
我将提供约会表的屏幕截图,以便您轻松了解我的问题。
答案 0 :(得分:0)
您发送的不是电话号码,而是查询您的短信服务。
$phone= "SELECT contact FROM service WHERE ID=$_POST[id]";
send_sms($phone,$message);
...
function send_sms($phone, $message) {
...
$parameters = array(
'apikey' => '*****************', //Your API KEY
'number' => $phone, /*"SELECT contact FROM service WHERE ID=$_POST[id]" */
'message' => $message,
'sendername' => 'SEMAPHORE'
);
在尝试向其发送消息之前,请运行查询并检索实际的电话号码。 (希望您的短信服务不知道如何处理您的查询。)
并且,请注意评论中的SQL注入警告。网络犯罪分子通常会在他们上线后不到一天的时间内点击像你这样的易受攻击的网站。公共互联网是一个危险的地方。您正在为您的短信服务付费。你不愿意收到20,000美元的账单,因为垃圾邮件发送者使用你的服务发送邮件。你更讨厌失去声誉。