Skip to content

Instantly share code, notes, and snippets.

@eresende
Created September 26, 2014 15:32
Show Gist options
  • Save eresende/4423f9f2c3a3f416e454 to your computer and use it in GitHub Desktop.
Save eresende/4423f9f2c3a3f416e454 to your computer and use it in GitHub Desktop.
Test IMAP connection
<?php
$mail_server = "mail.example.com" ;
$mail_username = "[email protected]" ;
$mail_password = "a very long and unbreakable password" ;
$mail_port = 143 ;
$mail_folder = 'INBOX';
echo "<h1>".$mail_username." on ".$mail_server."</h1>\n\n" ;
$mbox = imap_open("{".$mail_server.":".$mail_port."/imap/novalidate-cert}".$mail_folder, $mail_username, $mail_password) or die("Error opening mailbox: ".imap_last_error());
$mailboxheaders = imap_headers($mbox);
if ($mailboxheaders == false) {
echo "<p>".$mail_folder." is empty.</p>\n\n";
} else {
echo "<h2>".$mail_folder."</h2>\n" ;
echo "<ol>\n" ;
$msgno = 0;
foreach ($mailboxheaders as $val) {
$msgno++;
echo " <li>".$val ."</li>\n";
}
echo "</ol>\n\n" ;
}
imap_close($mbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment