'Connect Office 365 use POP3 - PHP

I have a trouble with Office 365 use POP3 method.

Currenty, I can't connect to this server:

   outlook.office365.com 
   port:995

This is my code example:

<?php
$host = 'outlook.office365.com';
$port = '995';
$username = 'outlook_mail';
$password ='password';
$mbox = imap_open('{'.$host.':'.$port.'/pop3/ssl/novalidate-cert}', $username, $password);

echo "<h1>Mailboxes</h1>\n";
$folders = imap_listmailbox($mbox, "{".$host.":".$port ."}", "*");

if ($folders == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($folders as $val) {
        echo $val . "<br />\n";
    }
}

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);

If I change port to 993, it's OK. Anyone know this problem? Many thanks!



Solution 1:[1]

I think it's because pop3 is on port 993 and imap is on port 995.

Have you tried with imap in your host config instead of pop3 when using port 995 ?

$mbox = imap_open('{'.$host.':'.$port.'/imap/ssl/novalidate-cert}', $username, $password);

Source : https://www.php.net/manual/en/function.imap-open.php (flag section)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mathieu LALLEMAND