-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>

I am trying to send an sms to the given number that i am taking from user or even if i am giving it a hardcore number, it is still not sending any sms to the provided mobile number. I have checked my dashboard and i have my credits still left there. So please help me to get out of this trouble in a beginner friendly way

  • Try: $message = "Hiii ".$name." Your OTP for creating account on HOUZZ is :".$otp; or you need to register your message in you Server provider DLT message aftr that you can send message – KHIMAJI VALUKIYA Dec 21 '21 at 14:30
  • `echo "OTP sent successfully";` - why are you outputting such a message, when you did not check the actual API response _at all_? – CBroe Dec 21 '21 at 14:33
  • i didn't understand what you are trying to say . I have done as of a youtube channel exactly. Can you please speak in a beginner friendly way. – MANISH KESHRI Dec 21 '21 at 14:36
  • @CBroe I have checked by commenting out that line , i am still not receiving any sms – MANISH KESHRI Dec 21 '21 at 14:39
  • @KHIMAJIVALUKIYA:- i didn't understand what you are trying to say . I have done as of a youtube channel exactly. Can you please speak in a beginner friendly way. step by step – MANISH KESHRI Dec 21 '21 at 14:41
  • _"I have checked by commenting out that line"_ - how is that _checking_ anything? You need to check what response the API gave you first of all - so do a `var_dump($result);` – CBroe Dec 21 '21 at 15:00
  • @CBroe : when i done var_dump($result) it isshowing :-string(72) "{"errors":[{"code":80,"message":"Invalid template"}],"status":"failure"}" – MANISH KESHRI Dec 21 '21 at 15:09
  • So according to https://api.textlocal.in/docs/sendsms, the full error description is _"80: Invalid Template. The message given didn't match any approved templates on your account."_ - so it looks like you'll need to go and get a template approved in your account first. – CBroe Dec 21 '21 at 15:13
  • @CBroe can you please tell me how it is done??? – MANISH KESHRI Dec 21 '21 at 15:22
  • No, I am not going to read the documentation of the service you want to use _for you_ now. – CBroe Dec 21 '21 at 15:25
  • This is what I am saying "[{"code":80,"message":"Invalid template"}]". In India If you want to send any SMS via SMS Gateway then you need to Create that SMS Format template in SMS Service API provider account. Once they verify template then you can send SMS via API. Here is the details of your SMS gateways DLT Configuration: https://www.textlocal.in/app/uploads/2020/09/DLT-Template-Registration-Process-Jio.pdf – KHIMAJI VALUKIYA Dec 21 '21 at 18:11
  • @KHIMAJIVALUKIYA but i just want to take the trial so for that i cannot pay money in advance to create a new template and i also donot know how to create a template so please help me in this – MANISH KESHRI Dec 21 '21 at 18:15
  • Please check Given PDF, I've added PDF URL in last message, check and follow the step. You need to create following DLT template(As per the test which you've written in Code): Hiii {#var#} Your OTP for creating account on HOUZZ is :{#var#} – KHIMAJI VALUKIYA Dec 21 '21 at 18:30
  • {#var#} is for Dynamic variable for Name, OPT and other dynamic variables. – KHIMAJI VALUKIYA Dec 21 '21 at 18:31
  • @KHIMANJI VALUKIYA will this take money to create a template as you suggested?? I am just trying it out and I am not using it for any business aur other purpose, I am just trying it – MANISH KESHRI Dec 22 '21 at 03:47

1 Answers1

0

According to the documentation of 'textlocal' here: https://www.textlocal.in/free-developer-sms-api/

The only required field you need to pass towards the API are:

  1. apikey [provided by textlocal]
  2. numbers [destination numbers]
  3. sender
  4. message

There is no 'apikey' in your parameter "$data", but only field that the API doesnot accepts, ie. username and password.

Vicky Maharjan
  • 318
  • 1
  • 7