Search code examples
phpsmshost

I want to recive the error code. by the sms host server in php


i want to receive errors from the sms host server curl_error curl_errno curl_strerror all these function returns error but not in the way i want , mysmshost say that you will receive code like, 202 for wrong mobile number, 301 for wrong authentication, i want to receive those error code please help. this is my code.

//sending message
        $authKey = "my_authentication_key";
        $senderId = "sender";
        $message = urlencode("Hello Its Working..");
        $route = "1";
        $campaign = 'Default';
    //Prepare you post parameters
$postData = array(
    'authkey' => $authKey,
    'mobiles' => $number,
    'message' => $message,
    'sender' => $senderId,
    'route' => $route,
    'campaign' => $campaign
);
//API URL
$url="http://sms.mysmshost.com/sendhttp.php";
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $postData
    //,CURLOPT_FOLLOWLOCATION => true
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
    echo curl_error($ch)."-curl_error<br/>";
    $chcode =curl_errno($ch); 
    echo $chcode;
    echo '<br/>error:' . curl_strerror($chcode)."<br/>";
}
curl_close($ch);
echo $output;

Curl_errorno() is not executing, even if i print them without if condition they give no result.


Solution

  • Try this

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
    
    $server_output = curl_exec($ch);
    curl_close($ch);
    
    print_r($server_output);