I am trying to use a sms gateway app for android called SMSGateway with a http header request using curl as below;

$curl_handle=curl_init();
        curl_setopt($curl_handle, CURLOPT_URL,"http://192.168.1.2:9090/sendsms?phone=$phone&text=$message1&password=xxxxxxxx");
        curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 10000);
        curl_setopt($curl_handle, CURLOPT_TIMEOUT,50000);
        curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0');
        $query = curl_exec($curl_handle);
        if($query){echo "Message Sent to $phone !<br>";}else{echo "Message Not Sent to $phone !<br>";echo 'Curl error: ' . curl_error($curl_handle)."<br>";}
        curl_close($curl_handle);

This works perfectly fine on my local system but it gets timed out when executing from server...

I need to know what is wrong...is it a curl issue ? should i use file_get_contents ? Actually I did try file_get_contents...did not work too..

Recommended Answers

All 8 Replies

It could be the link, the above would work only in the intranet. To connect to an external remote server, you must point the server to use the public IP. Anyway to get some extra information add:

curl_setopt($curl_handle, CURLOPT_VERBOSE, true);

That will print the requests and responses of both sides.

Thank for the response cereal. Finally someone made some sense. I did feel the same about the IP... though as an amateur i wasnt too sure i was thinking in the right direction. But I did change the IP address to public IP and added the curl_setopt line you mentioned. However, still does not connect. I still get the message Failed to connect to 182.70.76.188 port 9090: Connection timed out...

Ok, when connecting to your public IP from remote you're connnecting to the router, what you have to do is to redirect the connection from the router to the internal server IP, this is defined as network address translation (NAT).

In practice in your router there should be an interface in which you can define the internal IP and the port, so that the request comining from remote acts like this:

REMOTE_REQUEST ===> [ROUTER]PUBLIC_IP:PORT ===> [SMS SERVER]INTERNAL_IP:PORT

Another solution is to set the SMS server in the DMZ and expose it directly to the internet:

Check the documentation of your router, if you need help let us know the model and version.

Thats a lot of good information cereal. What I am doing is, I have downloaded the Android app on my Samsung Galaxy and then written a simple php code with curl to invoke the http link to send an sms message from a form. I then upload it to my server and run it from there. Honestly I am a novice. Is there a simple way to just tweak the code to ensure that when the http link is executed, it would simply ensure my message gets delivered ? Sorry to sound stupid but I am a noob at redirecting routers and fiddling with Server etc..hope you understand..

No problem, with patience we can try to fix it.

Until the SMS gateway is behind your router the only methods to access it directly are those already suggested in my previous answer.

There are other solutions among these: you could create a feed (for example an RSS feed) in the remote server to be read by your local system, or simply query the remote database, for example, every N minutes. The pros of this solution is that the remote server doesn't need to know the IP of the local server, nor your public IP. The cons is that the execution is not synchronous.

ooops..sorry again...for the confusion...but I am a bit lost here...

My local system being my cell phone ? How do I get my cell phone to read the feed or database and send a message when I send from the browser through remote server ?

Do I also understand right that there is no simple way of just using an http link in php code in a browser to send sms from my mobile through the SMS Gateway App I have installed in my phone ?

My local system being my cell phone ?

No, it should be a computer in your local network, this will use a script to get the information from the remote database, then it will connect to your cell phone, through the script you posted in your first post, basically it would look like this:

    # pulling from remote

    +----------------+       +--------+       +---------------------+
    |Remote Database |  <--> | Router |  <--> |     Local system    |
    +----------------+       +--------+       |[PC with PHP scripts]|
                                              +---------------------+

                                                      +            
                                                      |            
                                                      |            
                                                      v            

                                                +------------+     
                                                |SMS Gateway |     
                                                |  [Phone]   |     
                                                +------------+     

If, instead, you redirect the connection from the router to the SMS gateway, then you won't need a local server and you could submit the input directly to the gateway:

    # receiving from remote

    +----------------+        +----------------+      +-----------------+
    |Remote Database |  +-->  | Router         | +--> | SMS Gateway     |
    +----------------+        | Public IP:PORT |      | Private IP:PORT |
                              +----------------+      +-----------------+

As suggested in my first post check the documentation of your router about the NAT or DMZ configuration, and if you need help tell us model and version.

A part this I cannot help much further, for me this is more a network issue rather than programming. Maybe you want to ask support to the Networking forum:

commented: Very clear explanation +0

Cereal, thanks a ton for all your effort and time. You have been really patient. I have got a much better understanding now. Will def follow up on your advices.

Thanks again.

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.