TIGER
TIGER

Reputation: 2907

SMS sending URL Not working With curl

I am using below code to send SMS by php curl. From browser when I am running $apiURL it works fine for me. But using below code of curl it's not working. OI gtting O/P as string(0) "". Am I doing something wrong,please help me.

$conturyCode = "91";
$client_mobile = "96******18";
$new_centername = "Apple Hospital";
$address = "Lal Darvaja,ringroad,surat(394220)";
$center_mobile = "86******91";
$apiURL = "http://103.16.101.52:8080/bulksms/bulksms?username=abc-def&password=abc123&type=0&dlr=1&destination=".$conturyCode.$client_mobile."&source=ABC&message=Scheduled at ".$new_centername." and ".$address." and ".$center_mobile;

//  Initiate curl
$ch = curl_init();
//Set User client
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");

curl_setopt($ch, CURLOPT_VERBOSE, true);
// Set The Response Format to Json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
// Set Auto referer
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL, $apiURL);
// Execute
$result = curl_exec($ch);

// Check if any error occurred
if(curl_errno($ch))
{
    echo 'Curl error: ' . curl_error($ch);
}

// Closing
curl_close($ch);

var_dump($result);

Upvotes: 0

Views: 4886

Answers (3)

sandeep autade
sandeep autade

Reputation: 401

In my case below code worked successfully

$abc= 'http://bullet1.sdctechnologies.co.in:8080/api/mt/SendSMS?user='.$sms_username.'&password='.$sms_password.'&senderid='.$sms_sender_id.'&channel=Trans&DCS=0&flashsms=0&number='.$txt_mobile.'&text='.$message.'';

$url = str_replace(" ","%20",$abc);
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        $response = curl_exec($ch);
        curl_close($ch);

Upvotes: 0

Swapnil Punekar
Swapnil Punekar

Reputation: 197

Try the below code:

$message = urlencode("Scheduled at ".$new_centername." and ".$address." and ".$center_mobile);
$apiURL = "http://103.16.101.52:8080/bulksms/bulksms?username=abc-def&password=abc123&type=0&dlr=1&destination=".$conturyCode.$client_mobile."&source=ABC&message=".$message;

The message that you are passing needs to be url encoded.

Upvotes: 2

Sidharth Sharma
Sidharth Sharma

Reputation: 395

I haven't used that specific API, but I would recommend going with Nexmo's SMS API. This API can be easily integrated in your app, increase your delivery rate, and bring you peace of mind from that you're using the SMS API gateway trusted by large brand name apps/companies around the world.

Nexmo, where I work, has an SMS API allows you to easily send SMS messages to phones in over 200 countries.

The API is extremely reliable, safe, & easy to integrate in your application.

All you need to do is make a simple HTTP call.

You can check the pricing for each country here

Below is some sample code in PHP that will allow you to start sending texts around the world. After signing up for the free trial, replace your own api_key, api_secret, to, from, and text (along with any other optional parameters you may want).

<?php
$url = 'https://rest.nexmo.com/sms/json?' . http_build_query([
    'api_key' => API_KEY,
    'api_secret' => API_SECRET,
    'to' => YOUR_NUMBER,
    'from' => NEXMO_NUMBER,
    'text' => 'Hello from Nexmo'
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

Here's the documentation to send a message with Nexmo's SMS API

Upvotes: 2

Related Questions