I'm new using cURL, and I'm trying to send information from an HTTP form through cURL.
If I use $data_string
without the form, the code works. How can I pass the values of the form?
<?php
$data = array('dst_number' => 'dst_number','sms_content' => 'sms_content');
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.connectus.cl/api_v2/send_sms');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'xxxxxxxxxxxxxx:xxxxxxxxxxxxxx');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json')
);
if(curl_exec($ch) === false){
echo 'Curl error: ' . curl_error($ch);
}
$response = curl_exec($ch);
curl_close($ch);
//print $ch;
?>
<html>
<head>
<title>SMS</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<p>DESTINATARIO: <input type="text" value="" id="dst_number" name="dst_number" /></p>
<p>Mensaje: <input type="text" value="" id="sms_content" name="sms_content" maxlength="160" /></p>
<p><input type="submit" value="Send SMS" name="send" /></p>
</form>
</body>
</html>