0

Searched all through Server Fault and Stack Overflow, but cannot find any useful information regarding this issue I have. There are plenty of questions regarding getting connected to Exchange, but that's not where my issue is.

I am running php-imap (latest via composer) and have setup a PHP script to connect to Office 365/Exchange to check for bounced messages. The script executes and works correctly, however throws some confusing connection errors.

The basic script:

$imap_server    = 'outlook.office365.com';
$imap_folder    = 'INBOX';
$imap_user      = '((myemailaddress))';
$imap_pass      = '((mypasswrod))';

$mailbox = new PhpImap\Mailbox ('{' . $imap_server . '}' . $imap_folder, $imap_user, $imap_pass);

try {

    $mailsIds = $mailbox->searchMailbox('ALL', true);
    print_r ($mailsIds);

} catch(PhpImap\Exceptions\ConnectionException $ex) {
    echo "IMAP connection failed: " . $ex;
    die();
}

Output:

Array
(
    [0] => 47
    [1] => 49
    [2] => 51
    [3] => 53
    [4] => 55
    [5] => 57
    [6] => 59
)

Notice:  Unknown: Connection failed to MNZ-efz.ms-acdc.office.com,143: No route to host (errflg=1) in Unknown on line 0

Notice:  Unknown: Connection failed to MNZ-efz.ms-acdc.office.com,143: No route to host (errflg=1) in Unknown on line 0

Notice:  Unknown: Connection failed to MNZ-efz.ms-acdc.office.com,143: No route to host (errflg=1) in Unknown on line 0

Notice:  Unknown: Connection failed to MNZ-efz.ms-acdc.office.com,143: No route to host (errflg=1) in Unknown on line 0

EDIT:

Further - it appears all emails in the INBOX are being deleted upon execution of the script. Not sure why... but it seems it would have something to do with whatever is happening here in the background that is causing those errors.

Luke Pittman
  • 870
  • 4
  • 12
  • I'm pretty sure there's absolutely no way your sample script could delete messages in the inbox. In fact, I'm surprised it can login at all since O365 requires SSL or StartTLS. – Max Jul 25 '19 at 15:05
  • I agree Max. I ended up getting rid of PHP-Imap and just writing my own using PHP's built-in IMAP functions and the issue with the emails being deleted immediately went away. I still get those connection notices, but simply disabled the notices being displayed. Not the solution I wanted, but it is working. – Luke Pittman Jul 26 '19 at 16:02

0 Answers0