j_70,
I only toyed with IMAP before, but you can use PHP's imap_open command.
From the PHP imap_open() Manual Page:
// To connect to an SSL IMAP or POP3 server with a self-signed certificate,
// add /ssl/novalidate-cert after the protocol specification:
$mbox = imap_open ("{localhost:995/pop3/ssl/novalidate-cert}", "user_id", "password");
You can try that function, there is a few examples there.