phpsmsclickatell

Clickatell - redirect after the sms sent


i want to integrate ang sms notification after the form was submitted, and after the sms sent i want to redirect it to my thankyou.html web page, this is my code:

<?php
if(isset($_POST['send'])){
$query="insert into table() values() ";
if(mysql_query($query)){
 header("location:http://api.clickatell.com/http/sendmsg?api_id=3549342&user=xxxx&password=xxxx&to=63926475xxxx&text=xxxx ");
}
}
?>
<form method=post >
Username: input type=text name=user >
Password: <input type=text name=pass >
Name: <input type=text name=name >
Mobile number: <input type=text name=mobile_no >
<input type=submit name=submit >
</form>

Suppose that the query returned true, it will send the sms, using the clickatell api, i want is if the message is success i want it to redirect on my .html page that display "Thank You".

I am new to this api, Thank you!


Solution

  • Why not use file function here to retrieve the contents of the api url?

    <?php
      $url = "http://api.clickatell.com/http/sendmsg?api_id=3549342&user=xxxx&password=xxxx&to=63926475xxxx&text=xxxx";
    
      $data = file($url);
    
      $dataArr = explode(":",$data[0]);
    
      if ($dataArr[0] == "OK") 
      {
        //do the redirection here
        header("location:your.html");
        exit;
      } 
      else 
      {
        echo "Failed: ".$dataArr[1]; //apparently $dataArr[0] contains 'ERR' and has no details regarding the error.
      }
    ?>
    

    You can see the entire content received with

    print_r($dataArr);
    

    Here is the link to developer guide.