How can data be sent to an external form (POST) using PHP?
To send data to an external form using PHP, you can use the cURL library which allows you to make HTTP requests. You can use cURL to send a POST request to the external form with the data you want to submit.
$data = array(
'key1' => 'value1',
'key2' => 'value2'
);
$ch = curl_init('http://external-form-url.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
if($response === false){
echo 'Error: ' . curl_error($ch);
} else {
echo 'Data sent successfully!';
}
curl_close($ch);
Keywords
Related Questions
- Can using if statements and loops be a viable alternative to using built-in PHP functions for removing duplicate elements from an array?
- What are the potential drawbacks of using the PHP PDF library integrated into the server?
- Are there any potential drawbacks or limitations to artificially extending the execution time of a PHP function?