Pankaj Khurana
Pankaj Khurana

Reputation: 3271

Curl script not working for some of the url

I want to execute a url for which i am using curl.

I have following curl script:

$messageUrl = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=myusername&password=pass&sendername=sender&mobileno=mob&message=hi";
//$content=file_get_contents($messageURl);
$ch = curl_init($messageUrl);
$fp = fopen("message.txt", "w");

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

When i execute this script on my local server it runs fine that is the sms is sent to the user and message is successfully written to the message.txt file.

But when i upload it on the server (hostgator). It does not work.

I had a talk with hosting provider. Earlier curl was not enabled but was enabled after the conversation. Even then the above example does not run.

I tried to change the above code by calling the simple url: http://google.com. It executes properly on the server with some text written in the message.txt file .

I fail to understand the reason behind this.

Upvotes: 2

Views: 2751

Answers (7)

Jasmeet Singh
Jasmeet Singh

Reputation: 493

Use urlencode( $message ). Use urlencode() only for the message part of your URL. And as mentioned in other answers remove ":8080" from URL.

Upvotes: 0

Abhijeet
Abhijeet

Reputation: 1

The issue is with port 8080. The host is not responding on that port. You need to contact your hosting provider to open it. Or, you can just remove 8080 from the url.

Upvotes: 0

Mansi
Mansi

Reputation: 31

$messageUrl = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=myusername&password=pass&sendername=sender&mobileno=mob&message=hi";

Remove the 8080 port from the above url. It worked.

Upvotes: 3

Mayank
Mayank

Reputation: 1

This is the same problem I am facing with theSMS Mantra Http API.

The code works perfectly with local server installed at home location. But when you upload the code to the hosting server like GODaddy server then it will not work.

Probably GODaddy host server do not allow connection to port 8080 as a standard port.

Upvotes: 0

Ranty
Ranty

Reputation: 3362

Try this right before curl_close:

echo "Error CURL: " . curl_error($curl) . " \nError number: " . curl_errno($curl);

Upvotes: 1

KARASZI István
KARASZI István

Reputation: 31477

Probably you have firewall on the production server, which prevents the PHP script to open connection to the port 8080, and allows it to open to 80.

Try to fire up a telnet client, or simply open a port to 8080 to test it.

Example with telnet:

telnet bulksms.mysmsmantra.com 8080

Upvotes: 0

ghstcode
ghstcode

Reputation: 2912

You need to set CURLOPT_RETURNTRANSFER before setting CURLOPT_FILE.

try:

$messageUrl = "http://bulksms.mysmsmantra.com:8080/WebSMS/SMSAPI.jsp?username=myusername&password=pass&sendername=sender&mobileno=mob&message=hi";

$ch = curl_init($messageUrl);
$fp = fopen("message.txt", "w+");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
fclose($fp);

read_file('message.txt'); 

See if that works.

Upvotes: 0

Related Questions