1

Guys i have an issue in the following code. I need to send bulk sms to 24,000 mobile numbers. But if i send it after 150 number send it shows me an Internal server error and stop send other following numbers. Kindly go through the code given below and reply the positive code that can really help me.

<?php
//Code using fopen
//Change your configurations here.
//---------------------------------
$username = "username";
$api_password = "api_password";
$sender = "sender";
$domain = "domain";
$priority = "1";// 1-Normal,2-Priority,3-Marketing
$method = "POST";

//---------------------------------
for ($i = 0; $i < $var; $i++) {
    if (isset($_REQUEST['send'])) {

        $mobile = $explode_num[$i];
        $lenthof_number = strlen($mobile);
        if ($lenthof_number >= 10) {
            $message = $_REQUEST['message'];

            $username = urlencode($username);
            $password = urlencode($api_password);
            $sender = urlencode($sender);
            $message = urlencode($message);

            $parameters = "username=$username&api_password=$api_password&sender=$sender&to=$mobile&message=$message&priority=$priority";


            if ($method == "POST") {
                $opts = array(
                    'http' => array(
                        'method' => "$method",
                        'content' => "$parameters",
                        'header' => "Accept-language: en\r\n" .
                            "Cookie: foo=bar\r\n"
                    )
                );

                $context = stream_context_create($opts);

                $fp = fopen("http://$domain/pushsms.php", "r", false, $context);
            } else {
                $fp = fopen("http://$domain/pushsms.php?$parameters", "r");
            }

            $response = stream_get_contents($fp);
            fpassthru($fp);
            fclose($fp);


            if ($response == "")
                echo "Process Failed, Please check domain, username and password.";
            else
                echo "$response";


        }//third if
    }//second if


}//first if
}//main for

?>
J0e3gan
  • 8,740
  • 10
  • 53
  • 80
sunil sandeep
  • 21
  • 1
  • 8

2 Answers2

0

Probably your page exeeded the max execution time. Put following code on top of page and try:

ini_set("memory_limit","128M"); 
//ini_set("memory_limit","256M"); 
//this sets it unlimited
ini_set("max_execution_time",0); 
Vikas Umrao
  • 2,800
  • 1
  • 15
  • 23
  • it is working fine for me in local server,but i still have the same problem in online servers, i am using godaddy servers to send this and in local server i get a note for each and every sms sent and it is fopen(): Content-type not specified assuming application/x-www-form-urlencoded in C:\xampp\htdocs\travels\all_send_sms.php can you help me on this and in online server i get a 500 internal server error – sunil sandeep Nov 18 '13 at 11:03
  • There are two things : 1) first copy paste the url: http://$domain?username=$username&api_password=$api_password&sender=$sender&to=$mobile&message=$message&priority=$priority and check whether the sms is working or not. 2)secondaly you need to ask to your server providers(godaddy) to allow you to interact(allow permission) with your sms server domain.For this you can also try to change the permiisons of your file which have all the above code. – Vikas Umrao Nov 19 '13 at 03:55
0

Add this on the top of your PHP Script

<?php
set_time_limit(0);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126