How can one send an HTTP POST request in PHP?

To send an HTTP POST request in PHP, you can use the cURL extension, which allows you to make HTTP requests to a server. You need to set the CURLOPT_POST option to true, set the CURLOPT_POSTFIELDS option to the data you want to send in the request, and then execute the request using curl_exec.

$url = 'http://example.com/api';
$data = array('key1' => 'value1', 'key2' => 'value2');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if ($response === false) {
    echo 'Error: ' . curl_error($ch);
} else {
    echo 'Response: ' . $response;
}

curl_close($ch);