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);

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.

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.

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.

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.

Member Avatar for LastMitch

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.

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

Curl errors : couldn't connect to host

Member Avatar for LastMitch

@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?

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.

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.

Member Avatar for diafol

looks like absolutesms is dead

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.

Member Avatar for diafol

Example of fly-by post by the looks of it. Live and learn :)

Member Avatar for iLikePHP

@dheppell - Totally agree.

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.