PHP imap parsing, outlook error

I am trying to make an imap parser where it connects to the outlook server but when I run the code, I run into this error:

Warning: imap_open(): Couldn’t open stream {outlook.office365.com:143/STARTTLS}INBOX in C:\xampp\htdocs\Imap_parser1.php on line 49 Cannot connect to kraken.im: Can’t open mailbox {outlook.office365.com:143/STARTTLS}INBOX: invalid remote specification Notice: Unknown: Can’t open mailbox {outlook.office365.com:143/STARTTLS}INBOX: invalid remote specification (errflg=2) in Unknown on line 0
Would it be possible to get a solution on how to fix the problem please?

Kraken.im Email Parser <?php
//include Imap_parser class
include './Imap_parser1.php';
   //$myfile = fopen("Imap_parser.php", "r");

//create Imap_parser Object
$email = new Imap_parser();

//data
$data = array
(
    //email account
    'email' => array
    (
        'hostname' => '{outlook.office365.com:143/STARTTLS}INBOX',
        'username' => '[email protected]',
        'password' => 'STanks396'
    ),
    //inbox pagination
    'pagination' => array
    (
        'sort' => 'DESC', // or ASC
        'limit' => 3,
        'offset' => (empty($_GET['offset']) ? 0 : $_GET['offset'])
    )
);

//get inbox by pagination. Array
$result = $email->inbox($data);

//HTML
$html = '<table>';
$html .= '<tr><td>subject</td><td>form</td><td>email</td><td>date</td>                
<td>message</td><td>image</td></tr>';
foreach($result['inbox'] as $r)
{
    $html .= '<tr><td>'.$r['subject'].'</td><td>'.$r['form'].'</td>    
    <td>'.$r['email'].'</td><td>'.$r['date'].'</td><td>
    <pre>'.$r['message'].'</pre></td><td>'.(!empty($r['image'])? '<img 
    src="'.$r['image'].'"/>' : '').'</td></tr>';
} 

$html .= '</table>';

echo $html;

?>

class Imap_parser {

function inbox($data)
{

$result = array();

***$imap =  imap_open($data['email']['hostname'], $data['email']
['username'], $data['email']['password']) or die ('Cannot connect to 
kraken.im: ' . imap_last_error());***
array('DISABLE_AUTHENTICATOR' => 'GSSAPI');
array('DISABLE_AUTHENTICATOR' => 'PLAIN');

if ($imap) 
{

    $result['status'] = 'success';
    $result['email']  = $data['email']['username'];

    $read = imap_search($imap, 'ALL');

    if($data['pagination']['sort'] == 'DESC')
    {
        rsort($read);
    }

    $num = count($read);

    $result['count'] = $num;

    $stop = $data['pagination']['limit'] + $data['pagination']
    ['offset'];

    if($stop > $num)
    {
        $stop = $num;
    }

    for ($i = $data['pagination']['offset']; $i < $stop; $i++) 
    {

        $overview   = imap_fetch_overview($imap, $read[$i], 0);
        $message    = imap_body($imap, $read[$i], 0);
        $header     = imap_headerinfo($imap, $read[$i], 0);
        $mail= $header->from[0]->mailbox . '@' . $header->from[0]->host;
        $image = '';

        $message = preg_replace('/--(.*)/i', '', $message);
        $message = preg_replace('/X\-(.*)/i', '', $message);
        $message = preg_replace('/Content\-ID\:/i', '', $message);

        $msg = '';            

        if (preg_match('/Content-Type/', $message)) 
        {
            $message = strip_tags($message);
            $content = explode('Content-Type: ', $message);
            foreach ($content as $c) {
                if (preg_match('/base64/', $c)) 
                {
                    $b64 = explode('base64', $c);
                    if (preg_match('/==/', $b64[1])) 
                    {
                        $str = explode('==', $b64[1]);
                        $dec = $str[0];
                    } else 
                    {
                        $dec = $b64[1];
                    }
                    if (preg_match('/image\/(.*)\;/', $c, $mime)) 
                    {
                        $image = 'data:image/' . $mime[1] . ';base64,' . 
                        trim($dec);
                    }
                } else {
                    if (!empty($c)) 
                    {
                        $msg = $c;
                    }
                }
            }
        } else 
        {
            $msg = $message;
        }

        $msg = preg_replace('/text\/(.*)UTF\-8/', '', $msg);
        $msg = preg_replace('/text\/(.*)\;/', '', $msg);
        $msg = preg_replace('/charset\=(.*)\"/', '', $msg);
        $msg = preg_replace('/Content\-Transfer\-Encoding\:(.*)/i', '', 
        $msg);

        $result['inbox'][] = array
        (
            'id' => $read[$i],
            'subject' => strip_tags($overview[0]->subject),
            'from' => $overview[0]->from,
            'email' => $mail,
            'date' => $overview[0]->date,
            'message' => trim($msg),
            'image' => $image
        );

        $result['pagination'] = array
        (
            'sort' => $data['pagination']['sort'],
            'limit' => $data['pagination']['limit'],
            'offset' => array
            (
                'back' => ($data['pagination']['offset'] == 0 ? null : 
                 $data['pagination']['offset'] - $data['pagination']
                 ['limit']),
                'next' => ($data['pagination']['offset'] < $num ? 
                 $data['pagination']['offset'] + $data['pagination']
                 ['limit'] : null)
            )
        );

    }

    imap_close($imap);

} else 
{
    $result['status'] = 'error';
}

return $result;

}

office365 is normally connected to via SSL so try this instead:

[php]{outlook.office365.com:993/imap/ssl/novalidate-cert}Inbox[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service