Test/debug IMAP connection with PHP

Following is a basic code to get the last received e-mail using IMAP protocol:

ini_set('display_errors', 1);
error_reporting(E_ALL);

// Debug flag
$mail = imap_open('{mail.example.com:143/debug}', 'test@example.com', 'password');
// or using SSL/TLS $mail = imap_open('{mail.example.com:993/ssl/debug}', 'text@example.com', 'password');

$last_mail = imap_num_msg($mail);

var_dump(imap_headerinfo($mail, $last_mail));
echo imap_body($mail, $last_mail);

imap_close($mail);

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *