What potential issue might be causing the "HTTP request failed!" error in the PHP script?

The "HTTP request failed!" error in a PHP script could be caused by various issues such as network connectivity problems, incorrect URL, server-side issues, or incorrect request parameters. To solve this issue, you should check the URL, make sure the server is reachable, and ensure that the request parameters are correctly formatted.

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

$options = array(
    'http' => array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query($data)
    )
);

$context  = stream_context_create($options);
$response = file_get_contents($url, false, $context);

if ($response === false) {
    die('HTTP request failed!');
}

// Process the response here
?>