2

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.

1
  • It does not work does not explain anything. How do you know it doesn't not work? what have you tried? Commented Jan 13, 2012 at 11:48

7 Answers 7

3

$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.

Sign up to request clarification or add additional context in comments.

1 Comment

its really work for me.. i searched for all possible way for this, finally i decided to try this and it worked ..good
1

Try this right before curl_close:

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

Comments

0

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.

1 Comment

thanks sean for replying. i have modified the code according to your suggestion but still no success.
0

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

Comments

0

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.

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.