Creating IMAP Connection using PHP

I'm trying to create a script that will list emails in a mailbox with the end result being a cronjob setup to check the mailbox and save attachments depending on the subject contents - however I'm having trouble setting it up, could someone tell me where i'm going wrong or a more efficient way to establish a connection?

P.s I'm using 1and1 for my hosting.

CODE

<?php
$mbox = imap_open("{imap.ionos.co.uk:993}", "EMAILADDRESS", "ACCOUNTPASSWORD");

echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{imap.ionos.co.uk:993}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>

CURRENT OUTCOME Current Outcome


It turned out to be an easy fix, the mailbox uses SSL and my script didn't have anything for SSL. So I changed it to the below and it worked;

$mbox = imap_open ("{imap.ionos.co.uk:993/imap/ssl}INBOX", "EMAILADDRESS", "PASSWORD");