2

I tried to sent an SMS using an API with file_get_contents() in PHP.

Eg.

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");

In local machine it works well.

If i Put it in to server[SERVER A] its not working.If i change the code ie. file_get_contents("http://google.com"); it works fine in both server and local.

if i put this page ie

file_get_contents("http://testsmssite/SMS.php?username=xx&password=ccc&message=MESSAGE&numbers=1111111111&sender=11111");

in to another server[SERVER B] it works fine.

If it is any problem with my [SERVER A] then how it open google?

Can any one help me to fix this issue ?

Dan Grossman
  • 51,866
  • 10
  • 112
  • 101
AGK
  • 99
  • 1
  • 4
  • 12

4 Answers4

3

Instead of using file_get_contents, try using curl. See what you get back as a response and check curl_error. There are many possible reasons that could cause the request to fail.

Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
2

Check your error log. If file_get_contents fails, it tells you the reason why in the PHP error log if you log warnings and notices.

In a related question, Why doesn't file_get_contents work?, some have created a collaborative wiki answer that deals with how to trouble-shoot file_get_contents in detail. Maybe the infos and comments help you as well.

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
0

Can you check if allow_url_fopen is true/enabled, for more http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen? It could be a reason. And yes, Curl could be a better option.

Kumar
  • 5,038
  • 7
  • 39
  • 51
0

Check if http://testsmssite is accessible from Server A (try pinging it). Maybe you'll have to add it to /etc/hosts. Or maybe you have to change settings on testsmssite. IMO it's network issue, not related to PHP itself (since on server A PHP is able to load data from http://google.com)

Maxim Krizhanovsky
  • 26,265
  • 5
  • 59
  • 89