Hello,

<?php

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

$ozeki_user = "0013246594464";
$ozeki_password = "password";
$ozeki_url = "https://sms.xxxxx.com/send_sms.php?";

########################################################
# 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, 60);
    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.= '&mesg_to='.urlencode($phone);
      $url.= '&mesg='.urlencode($msg);

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

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

      return($response);
}

########################################################
# GET data from sendsms.html
########################################################

$phonenum = $_POST['recipient'];
$message = $_POST['message'];
$debug = true;

ozekiSend($phonenum,$message,$debug);

?>

I've a html form sendsms.html and the above code in sendsms.php. After entering details and clicking send in http:/xxxx.com/sendsms.html it goes to http:/xxxx.com/sendsms.php and in this page it displays

Request:
https://sms.xxxx.com/send_sms.php?username=0013246594464&password=password&mesg_to=919985673219&mesg=Hello=Lamiv+this+is+a+test+message


Warning: fsockopen() expects parameter 2 to be long, string given in /home/www/xxxx.com/sendsms.php on line 18
Response:

 ()

Please help.

Try using intval($args[2]) instead of just $args[2]

Hei ShawnCplus,

After changing $args[2] to intval($args[2]) it is showing an error. as follows :

Warning: fsockopen() [function.fsockopen]: unable to connect to :0 (Failed to parse address "") in /home/www/xxx.com/sendsms.php on line 18
Response:

Failed to parse address "" (0)

Hei ShawnCplus,

After changing $args[2] to intval($args[2]) it is showing an error. as follows :

That means you're passing it an empty host and port 0. So print_r your args array and make sure there's stuff actually in there.

I'm sorry.

Does that mean $arfs[2] has no value assigned?

No, it means that args doesn't contain what you think it contains so print_r the array and check to see what's in it.

Hei,

I did add a line

$fp = fsockopen($args[1], intval($args[2]), $errno, $errstr, 60);
print_r($args[2]); -- this one

I added this print_r($args[2]); before the code started and as above and checked twice but it still outputs the same error. I guess there is nothing assigned to the $args[2]. What should the port number be? and is the host which is the location of the sendsms.php on my gateways server?

Hi ShawnCplus,

The following is the code given to me as API by the sms provider.

$ch = curl_init();

//Replace YOUR-LOGIN with the login (email id or mobile number)
//Replace YOUR-PASSWORD with your password of sms site.
curl_setopt($ch,CURLOPT_URL, "https://sms.xxxx.com/send_sms.php?username=YOUR-LOGIN&password=YOUR-PASSWORD&mesg_to=TO-NUMBER&mesg=MESSAGE");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$buffer = curl_exec($ch);
curl_close($ch);

I din't know what to do with it.

So I got the code which I'm using now from another post in this forum.

I even tried pasting this url with my username and password and message,

h t tps://sms.xxxx.com/send_sms.php?username=YOUR-LOGIN&password=YOUR-PASSWORD&mesg_to=TO-NUMBER&mesg=MESSAGE

it works without all that code. But I want a form for that which should only ask the receiver's number and the message.

Okay so the version you have tried that is working, can you gimme an update of the code please so I know what is happenging now,
Thanks.
Ignore what I juts wrote :P

So where have you got args from?

I never found something like " $args[2]=something ". If this is what you asked.

And all the code what I have is above.

But the thing is $args[1] probably doesn't have a sufficient value because it hasn't come from anywere. You don't have to srt it's value like that but where has it's value been set. You just seemed to come up with $args from the middle of nowhere.

What are they supposed to be?

Also if there is somewhere were you have set it try $args[0] and $args[1] instead of $args[1] and $args[2]

Arrays start from zero. Unlike counting t ten etc. :P
(Only example I could conjour up)

Hmmm. try gettingthe script from scratch and starting again.

Arrays start from zero. Unlike counting t ten etc. :P
(Only example I could conjour up)

With preg_match array index 0 is the entire string that was matched, the rest are the matching groups.

Ooops didn't see the preg_match, my bad.

After changing the $args1 & 2 to 0 & 1, it is showing an error

"Unable to find the socket transport "https" - did you forget to enable it when you configured PHP? (52)"

After changing the $args1 & 2 to 0 & 1, it is showing an error

"Unable to find the socket transport "https" - did you forget to enable it when you configured PHP? (52)"

Using HTTPS (or TLS) would require the OpenSSL extension for PHP to be installed and enabled.

http://www.daniweb.com/search/search.php?q=php+openssl

Hi,

Is that done by removing a ";" before the openssl thing from php.ini file? If it is so I've done that and still getting the same error.

When I asked the host for it, the support team said we don't sell ssl certificates. If that is related with a certificate I shall buy one.

And I have another host where he said "OpenSSL is enabled in PHP". Still I get the same error. Please help.

Hi,

Is that done by removing a ";" before the openssl thing from php.ini file? If it is so I've done that and still getting the same error.

When I asked the host for it, the support team said we don't sell ssl certificates. If that is related with a certificate I shall buy one.

And I have another host where he said "OpenSSL is enabled in PHP". Still I get the same error. Please help.

On windows removing ; before

extension=php_openssl.dll

in php.ini doesn't seem to be enough. You may have to build OpenSSL support into the PHP source.

see problems already mentioned:

http://www.daniweb.com/search/search.php?q=php+openssl

Its best you go with a host already offering it.

You don't need to purchase an SSL certificate. This is only required for servers, not for an SSL client like your PHP code.

First make sure you have OpenSSL installed.

<?php phpinfo(); ?>

And search for "openssl".

or via command line:

php -i | grep openssl

Then in your code use "tls" instead of "https" in fsockopen().

Hi,

with phpinfo() I found the following

Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7a FrontPage/5.0.2.2635 mod_bwlimited/1.4 mod_auth_passthrough/2.1 PHP/5.2.5

Hi,

with phpinfo() I found the following

Did you try replacing https with tls?

ie:

$ozeki_url = "https://sms.xxxxx.com/send_sms.php?";

to

$ozeki_url = "tls://sms.xxxxx.com/send_sms.php?";

yes, I changed https to tls as u specified, still it gives me the same error. when asked the host, the support replied it mite be a problem with php and mysql being version 5, ur site has to be moved to a php and mysql version 4 server. shall I opt for the change? and what would the bad part be if any while opting for lower version server?

Could you post the code as you currently have it please?

You really want PHP5. PHP4 is no longer supported by the PHP development team except for security fixes. PHP5 is faster, its more secure, it has better language features, in addition to being supported.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.