0

My problem is somehow peculiar. I have this bulksms api from my provider:

http://www.estoresms.com/smsapi.php?username=user&password=1234&sender=@@sender@@&recipient=@@recipient@@&m
essage=@@message@@&

then i wrapped it in PHP and passed it in cURL:

$api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it =  curl_get_contents($api);

ordinarily, it worked fine, but when $recepient (phone numbers) are more than say 300, i get an error:

Request-URI Too Long The requested URL's length exceeds the capacity limit for this server. Additionally, a 414 Request-URI Too Long error was encountered while trying to use an ErrorDocument to handle the request.

But BulkSMS should be able to send to thousands of numbers at a time. From my research, i found out that there's a limit to URL. I'm not the server owner. i working on a shared hosting plan. pls how can i get around this problem. I know there's a solution to it that would not mean buying my own server.

Thanks

david
  • 39
  • 7

3 Answers3

0

Can you try to make the API use POST instead of GET. It would solve the issue.

Edit:

I'm not sure your API check POST, but try that:

$api = "http://www.estoresms.com/smsapi.php";
$data = array('username' => $sms_user, 'password' => $sms_pwd, 'sender' => $sender_id , 'recipient' => $numbers , 'message' => $text);

function curl_get_contents($url)
{   
$ch = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$send_it =  curl_get_contents($api);
m.nachury
  • 972
  • 8
  • 23
  • Pls how can I go about using POST? Thanks – david Jul 11 '17 at 17:50
  • i've tried it, it didn't work. Even for any numbers, whether few or many. My original code works. The problem is when the numbers are so many, it fails. – david Jul 13 '17 at 06:14
  • That means the API doesn't read POST data, that's weird since As I understood it, it's they're served that bloke the request? – m.nachury Jul 13 '17 at 07:02
  • I think it's one of two possibilities, 1st: that's the ways (a weird way) for the API to limit the number of phone numbers. 2nd: You pass through a proxy that make the blockage – m.nachury Jul 13 '17 at 07:03
  • If it's the 1st one try contacting the API and exposing them your issue. – m.nachury Jul 13 '17 at 07:04
0

Have a look at this code example (from bulksms.com).

http://developer.bulksms.com/eapi/code-samples/php/send_sms/

Willem
  • 917
  • 7
  • 19
0

So then, i had to find a way around my own problem. if the API will not allow thousands of numbers at a time, then let's break it into chunks at the point of execution.

    function curl_get_contents($url)
    {   
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
    }

    $how_many = count(explode(',',  $numbers));
    if ($how_many > 250){
    $swi = range(0, ceil($how_many/250)-1); 
    foreach ($swi as $sw){$numbers_a = implode(',', (array_slice(explode(',', $numbers), $sw*250, 250)));
    $api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers_a."&message=".$text."&";


    $send_it =  curl_get_contents($api);
    }
    }

if ($how_many <= 250){
    $api = "http://www.estoresms.com/smsapi.php?username=".$sms_user."&password=".$sms_pwd."&sender=".$sender_id."&recipient=".$numbers."&message=".$text."&";
$send_it =  curl_get_contents($api);    
}
david
  • 39
  • 7