PHP IMAP交换问题 [英] PHP IMAP Exchange Issue

查看:86
本文介绍了PHP IMAP交换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我目前正在编写的PHP脚本有一些问题.首先,让我说该脚本应该连接到IMAP邮箱,搜索一些电子邮件并下载其附件.所有这些都已经被编码,并且正在使用我自己的gmail帐户.当我尝试连接到交换服务器时会出现问题.简短的代码摘录:

So I have a little problem with a PHP script I'm currently writing. To start off, let me say the script is supposed to connect to an IMAP mailbox, search for some emails and download their attachments. All of this is already coded and is working with my own gmail account. The problem arise when I try and connect to an exchange server. Short code excerpt :

$mbox = imap_open($host, $login, $password);
echo '<br/>' . imap_last_error() . '<br/>';
$emails = imap_search($mbox, 'FROM "patate@patate.com"', SE_UID);

我尝试了两个主要的$ host版本"(带有和不带有SSL):

I have tried two main $host "version" (with and without SSL) :

1-{服务器:993/imap/ssl/novalidate-cert}收件箱 2-{server:143/imap/novalidate-cert}收件箱

1 - {server:993/imap/ssl/novalidate-cert}INBOX 2 - {server:143/imap/novalidate-cert}INBOX

novalidate-cert处理证书错误.我还尝试了这两个参数的"notsl"参数,但没有任何明显的结果.我得到的错误是这条可爱的消息,绝对不以任何方式,形状或形式都是晦涩的:

The novalidate-cert deal with a certificate error. I also tried the "notsl" parameters, for both of these, without any noticeable outcome. The error I get is this lovely message, absolutely not cryptic in any way, shape or form :

[CLOSED] IMAP connection broken (server response)

此外,我还会收到以下通知:

Additionally, I also receive these notices :

Notice: Unknown: Unknown GSSAPI failure: An invalid name was supplied (errflg=1) in Unknown on line 0 
Notice: Unknown: GSSAPI mechanism status: Hostname cannot be canonicalized (errflg=1) in Unknown on line 0 
Notice: Unknown: Retrying PLAIN authentication after AUTHENTICATE failed. (errflg=1) in Unknown on line 0 
Notice: Unknown: Retrying PLAIN authentication after AUTHENTICATE failed. (errflg=1) in Unknown on line 0 
Notice: Unknown: Can not authenticate to IMAP server: AUTHENTICATE failed. (errflg=2) in Unknown on line 0 
Notice: Unknown: [CLOSED] IMAP connection broken (server response) (errflg=1) in Unknown on line 0

前两个特别困扰我...我确实在另一台服务器上尝试了此脚本,以确保问题与我的本地网络无关.经过大量的搜寻之后,我才得到以下内容: http://www.phpfreaks .com/forums/index.php?topic = 190628.0 似乎有点麻烦.

The first two especially puzzle me... I did try this script on another server, to make sure the issue was not related to my local network. After a lot of googling around, I only got this : http://www.phpfreaks.com/forums/index.php?topic=190628.0 which seems like a somewhat cumbersome fix.

有什么想法吗?

推荐答案

我遇到了同样的问题,因为Exchange服务器发布了它不支持的身份验证协议,因此看起来好像正在生成错误(http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Exchange ) .似乎这个问题是隔离到Linux服务器的,因为我对Windows盒子上完全相同的代码没有任何疑问.这是一个长期存在的问题,最近对PHP(v 5.3.2)进行了修补,以允许您禁用某些身份验证协议(

I'm having this same issue, it looks like the errors are being generated because an Exchange server advertises authentication protocols that it does not support (http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Exchange). It also seems like this issue is isolated to linux servers as I have no issues with the exact same code on a Windows box. This has been a longstanding issue and PHP was recently patched (v 5.3.2) to allow you to disable certain authentication protocols (http://php.net/manual/en/function.imap-open.php). The below code works intermittently for me:

$this->inbox = imap_open("{server:993/imap/ssl/novalidate-cert}$inbox", 
                           $username, $password, NULL, 1, 
                           array('DISABLE_AUTHENTICATOR' => 'PLAIN')) or 
                   die(var_dump(imap_errors()));

这也可以间歇性地起作用:

This also works intermittently:

$this->inbox = imap_open("{server:993/imap/ssl/novalidate-cert}$inbox", 
                           $username, $password, NULL, 1, 
                           array('DISABLE_AUTHENTICATOR' => 'GSSAPI')) or 
                   die(var_dump(imap_errors()));

所以我贫民窟操纵了它,它似乎确实起作用了……尽管它可能对我公司的交换服务器造成无限循环/DOS攻击,但/care

SO I ghetto rigged this it does seem to work...although it has the potential for an endless loop/DOS attack on my company's exchange server but /care

希望有一个更好的解决方案,但这应该有所帮助:

Hopefully there is a better solution, but this should help:

$tryCnt = 0;

while(!is_resource($this->inbox)){

    $this->inbox = imap_open("{server.com:993/imap/ssl/novalidate-cert}$inbox", 
                               $username, $password, NULL, 1, 
                               array('DISABLE_AUTHENTICATOR' => 'GSSAPI'));
    $tryCnt ++;

    if(!is_resource($this->inbox)){

        $this->inbox = imap_open("{server.com:993/imap/ssl/novalidate-cert}$inbox", 
                                   $username, $password, NULL, 1, 
                                   array('DISABLE_AUTHENTICATOR' => 'PLAIN'));
        $tryCnt ++;

    }

    if($tryCnt > 20){

        echo "Cannot Connect To Exchange Server:<BR>";
        die(var_dump(imap_errors()));

    }    
}

这篇关于PHP IMAP交换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆