Major IMAP services aren’t connecting to imap_open() in PHP

I’m at my wit’s end. When connecting to a major IMAP services in PHP, I get a “Connection refused” error. I don’t understand why this is happening.

I have tried iCloud (imap.mail.me.com), Yahoo! (imap.mail.yahoo.com), Gmail, (imap.gmail.com), Outlook (outlook.office365.com) and even Yandex to connect to my PHP script.

$email = '[email protected]';
$password = 'my app pass word';

$imap_host = '{imap.gmail.com:993/imap/ssl}INBOX'; //Gmail
$connection = imap_open($imap_host, $email, $password);

if ($connection === false) {
    die('Failed to connect to Gmail: ' . imap_last_error());
}

What am I doing wrong? However, using my domain’s IMAP works fine. Do they block IMAP connections?

P.S. The IMAP extension is installed. I am using shared web hosting with cPanel.