I am getting this error while working on curl code

Warning: curl_setopt() expects parameter 1 to be resource, string given in C:\xampp\htdocs\

<?php
//initialize the request variable
$request = "";
//this is the username of our TM4B account
$param["username"] = "kacs";
//this is the password of our TM4B account
$param["password"] = "698117";
//this is the message that we want to send
$param["msg"] = "This is sample message.";
//these are the recipients of the message
$param["to"] = "90138933";
//this is our sender
$param["from"] = "SHRDIA";

//traverse through each member of the param array
foreach($param as $key=>$val){
	//we have to urlencode the values
	$request.= $key."=".urlencode($val);
	//append the ampersand (&) sign after each paramter/value pair
	$request.= "&";
}
//remove the final ampersand sign from the request
$request = substr($request, 0, strlen($request)-1);
//this is the url of the gateway's interface
$url = "http://abulksms.com/pushsms.php";
//initialize curl handle
$ch = curl_init;
curl_setopt($ch, CURLOPT_URL, $url); //set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable
curl_setopt($ch, CURLOPT_POST, 1); //set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //set the POST variables
$response = curl_exec($ch); //run the whole process and return the response
curl_close($ch); //close the curl handle
//show the result onscreen for debugging
//print $response;
 ?>

Recommended Answers

All 4 Replies

Try using parenthesis

$ch = curl_init();

Try using parenthesis

$ch = curl_init();

Thanks
I am trying to send SMS using HTTP but getting nothing. My code is

<?php
    function sendSMS($mobile, $msg, $sender, $sendPass, $sendID)
    {
        $msg=urlencode($msg);
        $ch = curl_init();
        $url="http://abulksms.com/pushsms.php?username=kacs&password=698117&sender=SHRDATIA&to=$mobile&message=$msg";
        echo $url;
        //$url=urlencode($url);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_POST, 1)or die("error1");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
        //return substr($data,0,1);
    }
   
   
    // call function on form submition
   
    sendSMS("9210485810","Hi! Type Your Message Here","kacs","698117","SHRDATIA");
   
    //pass varaible
    //sendSMS($mobileno, $msg, $user, $pass, $senderid);
?>

Please suggest me any idea for sending sms

comment following 2 lines, Your url do not need post fields

// curl_setopt($ch, CURLOPT_POST, 1)or die("error1");        
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

Also you may try without encoding url

comment following 2 lines, Your url do not need post fields

// curl_setopt($ch, CURLOPT_POST, 1)or die("error1");        
// curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

Also you may try without encoding url

Thanks a Lot urtrivedi

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.