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.