0

this is my sendmsg coding page. Am i right? its not working. First i got fatal error: call undefined function curl_init(). i cleared that error. now it takes time to load 10 to 15 seconds and show error in that page. coding is below...

$name = $_POST['name'];
$connum = $_POST['connum'];
$email = $_POST['email'];
$msg = $_POST['msg'];

$msg = "$name $connum $email";

$from = "FROM";
$to = "9876543210";
$username = "xxx";
$password = "yyy";
$hash = "RjK=H4kL";
$formcountry = "91";
$sourceinfo = "1";

$url = "http://absolutesms.com/Sendsms.aspx";
$fields = array ( 'from'=>urlencode($from), 'to'=>urlencode($to), 'username'=>urlencode($username), 'password'=>urlencode($password), 'hash'=>urlencode($hash), 'formcountry'=>($formcountry), 'sourceinfo'=>($sourceinfo) );

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

$result = curl_exec($ch);

if(!$result)
{
    echo "Error";
}
else
{
    echo "Message Sent Successfully";
}

curl_close($ch);
7
Contributors
14
Replies
71
Views
3 Years
Discussion Span
Last Post by iLikePHP
0

What is the error? Right now your code just prints "Error" if the curl_exec isn't successfull. You need to have it print or log the actual error message. Look into the curl_error function to get that.

The first thing you should always look at when you get an error is the error message. That is the key piece of evidence that will help you solve it.

0

I have built a couple of apps with this api but as above, I can't help you with anything unless I know the exact error.

0

Hi,

The remote server response is stored in $result, if you want to find out what is the error respnse from http://absolutesms.com/Sendsms.aspx , try using print_r or var_dump($result) on your side. If response is something like "missing cookie or session", you will have to provide a cookiejar and cookie text file for your cURL to utilize.

Edited by veedeoo: info added

0

The remote server response is stored in $result

That is not alwasy the case, and in this case it is not. The curl_exec function, by default, returns a boolean value, and directly outputs the result of the request to the output buffer. Only if you set the CURLOPT_RETURNTRANSFER option to true does it return the response on success, and it is not set in this code.

In any case, in the OPs case the curl_exec call is clearly returning FALSE, rather than any value that would evaluate as true - which would include just about any typical server response - so printing the return value would do little good other than to confirm that the request failed. The proper way to see the error message in this case is to use the curl_error function.

Edited by Atli

0

this is my sendmsg coding page. Am i right? its not working. First i got fatal error: call undefined function curl_init(). i cleared that error. now it takes time to load 10 to 15 seconds and show error in that page. coding is below...

@Indians

Did you installed the CURL extension?

Another words did you set-up CURL on your host server?

If you did set-up CURL correctly that error wouldn't appear. I feel you either you didn't set-up correctly or didn't know.

Read this to set-up CURL:

http://nz1.php.net/manual/en/curl.setup.php

Once you set-up the CURL extension, that error message will disappear.

Edited by LastMitch

0

@Atli, @fheppell, @LastMitch
i cleared that fatal arror.
now i got this following error...

Curl errors : couldn't connect to host

0

@Indians

Curl errors : couldn't connect to host

That error means there's a firewall blocking your connection.

Ask you host server how to enable the CURL setting with the firewall on.

Does that make sense?

0

It could also just mean that the URL is invalid or that there is a connection problem on the server-side; it could be that it's just to busy to respond before the CURL connection timeout is reached.

I don't know about you guys, but I can't seem to connect to the absolutesms.com domain at all. It always times out.

0

I can't seem to connect to it either. Personally I think you should use a more mainstream provider like Twilio. They have a ton of docs and example code and are going to have a much higher uptime.

0

Would be helpful if Indians actually replied. I'd hate to think that they're waisting their time on this instead of intergrating with a service that actually works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.