-1
my php code:-
<?php
if(isset($_POST['sendOtp'])){
    // Authorisation details.
    $username = "mkeshri185@gmail.com";
    $hash = "9432e86b7b39f209b427ae9bdc3b622373966fb0c7a804cda7adf4feda4f5648";

    // Config variables. Consult http://api.textlocal.in/docs for more info.
    $test = "0";
    $name = $_POST['name'];


    // Data for text message. This is the text message data.
    $sender = "TXTLCL"; // This is who the message appears to be from.
    $numbers = $_POST['mobile']; // A single number or a comma-seperated list of numbers
    $otp = mt_rand(100000 , 999999);
    setcookie('otp' , $otp);
    $message = "Hiii".$name."Your OTP for creating account on HOUZZ is :".$otp;
    // 612 chars or less
    // A single number or a comma-seperated list of numbers
    $message = urlencode($message);
    $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
    $ch = curl_init('http://api.textlocal.in/send/?');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch); // This is the result from the API
    echo "OTP sent successfully";
    curl_close($ch);



}


    if(isset($_POST['verifyOtp'])){
        $enteredOtp = $_POST['verify'];
        if($enteredOtp == $_COOKIE['otp']){
            echo 'correct otp';
        }else{
            echo 'inavlid otp';
        }
    }
?>


<!doctype html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

    
    <style>
    .form-Box {
        width: 50vh;
        /* display: relative; */
        position: relative;
        top: 30%;
        left: 5%;
        /* height: 100%; */
        width: 50%;
        align-items: center;
        margin: auto;
        justify-content: center;
        
    }

    .container {
        background-color: #43ba81;
        height: 100vh;
    }
    </style>

    <title>HOUZZ-Modern Way for living </title>
    <link rel="icon" href="../_utilityimages/title.svg" type="image/x-icon">
</head>

<body>
    <div class="container">
        <h2 style="text-decoration:underline; text-align: center; position:relative; top:20%;">Let's Begin Your Journey Here</h2>
        
        <div class="form-Box">

            <form action="_otp.php" method="POST">
                <span>Enter Your Name</span>
                <br>
                <br>
                <div class="input-group mb-3" style="width: 80%;">
                    <span></span>
                    
                    <input type="text" name="name" class="form-control" placeholder="Enter Your Name">
                </div>
                <span>Enter Your Mobile Number</span>
                <br>
                <br>
                
                <div class="input-group mb-3" style="width: 80%;">
                    <span class="input-group-text" id="basic-addon1">+91</span>
                    <input type="text" name="mobile" class="form-control" placeholder="Enter Your Mobile Number" aria-label="Username"
                        aria-describedby="basic-addon1">
                </div>
                <button type="submit" name="sendOtp" class="btn btn-primary">Send OTP</button>
                <br>
                <br>
                <span>Enter The OTP sent to your Mobile Number</span>
                <br>
                <br>
                <div class="input-group mb3" style="width: 80%;">
                    <input type="text" name="verify" class="form-control" placeholder="Enter sent OTP" aria-label="Username"
                    aria-describedby="basic-addon1">
                </div>
                <br>
                <button type="submit" name="verifyOtp" class="btn btn-primary">Verify OTP</button>
            </form>
        </div>
    </div>



    <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
    </script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
    -->
</body>

我正在尝试向我从用户那里获取的给定号码发送短信,或者即使我给它一个核心号码,它仍然没有向提供的手机号码发送任何短信。我检查了我的仪表板,我的积分还留在那里。所以请帮助我以对初学者友好的方式摆脱这个麻烦

4

1 回答 1

0

根据此处“textlocal”的文档: https ://www.textlocal.in/free-developer-sms-api/

您需要传递给 API 的唯一必填字段是:

  1. apikey [由 textlocal 提供]
  2. 号码 [目的地号码]
  3. 发件人
  4. 信息

您的参数“$data”中没有“apikey”,但只有 API 不接受的字段,即。用户名和密码。

于 2021-12-21T15:14:55.263 回答