Swati Sharma Swati Sharma - 1 year ago 122
Ajax Question

To use sms sending api on click of button

I have a php form which makes an ajax call on click of sumbit button to save data in database. I want to call sms api to send these details on click of the same submit button. How do I do that?

I am using it from http://sms.hspsms.com/.

Here is the script which takes data annd save it to database:

$(function () {
$('#user-form').on('submit', function(e) {

type: 'post',
url: './user-details.php',
data: $('#user-form').serialize(),
success: function () {

Where do I use sms api like:


to send the details entered in the form.

Edit: I found the solution and it is posted as an answer.

Answer Source

I did it using this:

 $url = "http://sms.hspsms.com:/sendSMS";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=xxx&password=xxx&to=XXXXX&message=' . $phone . '&sendername=xxx&smstype=TRANS&numbers=xxxx&apikey=xxx');
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        echo $result;

inside user-details.php