如何在存储在数据库中的多个号码上发送短信

时间:2014-05-25 09:15:44

标签: php

这是我的代码,我用作外部文件包含在我的代码中作为外部文件。当新用户发布此代码但未在存储在数据库中的所有数字上发送消息时:

错误是:

  

警告:fsockopen()[function.fsockopen]:无法连接到:0

     

(无法在C:\ xampp \ htdocs \ funsmss \ location \ sendsms.php中解析地址“”)   无法解析地址“”(0)

以下是代码:

    <?php   
     $sql   = "select * from subscribe where type ='$cat' and city ='$city'";
     $query = mysql_query($sql);

  if ($query != null) {
    while ($row = mysql_fetch_array($query)) {
    $name      = $row['name'];

    $phoneNum  = $row['fone'];
    $message   = "Hi ".$name.", now you can buy your product.";

    ozekiSend($phoneNum, $message);

    // for debugging, try the following line
    //echo ozekiSend($phoneNum, $message, true);
     }
   }

 ########################################################
 # Login information for the SMS Gateway
 ########################################################

 $ozeki_user     = "admin";
 $ozeki_password = "abc123";
 $ozeki_url      = "http://127.0.0.1:9501/api?";

 ########################################################
 # Functions used to send the SMS message
 ########################################################

  function httpRequest($url)
 {
$pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern, $url, $args);
$in      = "";
$fp      = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
    return("$errstr ($errno)");
} else {
    $out = "GET /$args[3] HTTP/1.1\r\n";
    $out .= "Host: $args[1]:$args[2]\r\n";
    $out .= "User-agent: Ozeki PHP client\r\n";
    $out .= "Accept: */*\r\n";
    $out .= "Connection: Close\r\n\r\n";

    fwrite($fp, $out);
    while (!feof($fp)) {
        $in.=fgets($fp, 128);
    }
    }
    fclose($fp);
     return($in);
  }

  function ozekiSend($phone, $msg, $debug = false)
  {
 global $ozeki_user, $ozeki_password, $ozeki_url;

$url = 'username=' . $ozeki_user;
$url.= '&password=' . $ozeki_password;
$url.= '&action=sendmessage';
$url.= '&messagetype=SMS:TEXT';
$url.= '&recipient=' . urlencode($phone);
$url.= '&messagedata=' . urlencode($msg);

$urltouse = $ozeki_url . $url;
if ($debug === true) {
    echo "Request: <br>$urltouse<br><br>";
}

//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug === true) {
    echo "Response: <br><pre>" .
    str_replace(array("<", ">"), array("&lt;", "&gt;"), $response) .
    "</pre><br>";
}

return($response);
 }
 ?>

0 个答案:

没有答案