使用Curl通过PHP发送短信

使用Curl通过PHP发送短信,php,jquery,ajax,curl,Php,Jquery,Ajax,Curl,我在下面有一个表单,假设它向后端发送一个POST请求,在提交时,后端将发送一条SMS: <form id="sms" method="post"> <input type="number" name="mobile" id="mobile" class="text"/> <button type="button" name="sub" value="Submit">Send</button> </form> 有

我在下面有一个表单,假设它向后端发送一个POST请求,在提交时,后端将发送一条SMS:

<form id="sms" method="post">
      <input type="number" name="mobile" id="mobile" class="text"/>
      <button type="button" name="sub" value="Submit">Send</button>
</form>

有人能给我指一个可以处理这些信息的PHP处理器吗?我的知识非常有限。

希望您可以直接与后端人员交谈,但据我所知,他们要求您使用javascript创建一个POST请求,该请求与示例中的curl命令执行相同的操作

表单不能按原样工作,因为它将使用编码表单将请求发送到后端,但后端需要JSON

您需要捕获表单提交,然后执行以下操作

url = 'https://example.com/gateway/sms';
data = {mobile: _get_number_from_form() };
success = function(data) { console.log(data); };
headers = {s: 'APP'};
jQuery.ajax({
    type: 'POST',
    url: url,
    data: data,
    success: success,
    dataType: 'json',
    headers: headers
});

Chrome中的“网络”选项卡在这里很有用。

PHP无法单独发送短信。您需要为此使用一些服务,而询问关于非现场服务的建议在这里是离题的,所以。你需要自己做研究,好的。谢谢。你真的要发邮件到吗https://example.com,或者这是您正在使用的实际服务的占位符?这是实际工作URL的占位符。这是正确的。我对这个比较陌生。所以我必须将JSON格式的数据发送到后端?我最初的想法是创建一个PHP表单处理器并发送手机号码,其余的由后端处理。不管怎样,我都不知道该怎么做。但是我也不能理解你的代码。非常感谢你。我正在网上寻找解决方案。是的,如果curl命令是我们所要做的全部。我上面给出的jQuery示例将javscript dict正确地转换为JSON。让我进一步搜索,看看是否有现成的解决方案。事实上,这是我无法理解的。非常感谢。在您的心智模型中,PHP表单处理器与后端其余部分之间的关系是什么?我假设您的PHP表单处理器位于后端。也许本教程可以澄清一些问题:
 $inNumber = $_REQUEST["inNumber"];
 $sender = $_REQUEST["sender"];
 $keyword = $_REQUEST["keyword"];
 $content = $_REQUEST["content"];
 $email = $_REQUEST["email"];
 $credits = $_REQUEST["credits"];

// Account details
        $apiKey = urlencode('jpvpyVsTv50-O7te5yiz3oP1DjMkdsiuHSUBS');

        // Message details
        $numbers = $_REQUEST["sender"];
        $sender = urlencode('JHSSVE');

        $text = "Thank you for your order";
        $message = rawurlencode($text);
     $test = true;

        // Prepare data for POST request
        $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

        // Send the POST request with cURL
        $ch = curl_init('https://api.textlocal.in/send/');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);
 $inNumber = $_REQUEST["inNumber"];
 $sender = $_REQUEST["sender"];
 $keyword = $_REQUEST["keyword"];
 $content = $_REQUEST["content"];
 $email = $_REQUEST["email"];
 $credits = $_REQUEST["credits"];

// Account details
        $apiKey = urlencode('jpvpyVsTv50-O7te5yiz3oP1DjMkdsiuHSUBS');

        // Message details
        $numbers = $_REQUEST["sender"];
        $sender = urlencode('JHSSVE');

        $text = "Thank you for your order";
        $message = rawurlencode($text);
     $test = true;

        // Prepare data for POST request
        $data = array('apikey' => $apiKey, 'numbers' => $numbers, "sender" => $sender, "message" => $message);

        // Send the POST request with cURL
        $ch = curl_init('https://api.textlocal.in/send/');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $response = curl_exec($ch);
        curl_close($ch);