PHP IMAP 交换问题

发布于 2024-11-03 12:08:40 字数 1678 浏览 5 评论 0原文

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

$mbox = imap_open($host, $login, $password);
echo '<br/>' . imap_last_error() . '<br/>';
$emails = imap_search($mbox, 'FROM "[email protected]"', SE_UID);

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

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

novalidate-cert 处理证书错误。我还尝试了“notsl”参数,对于这两个参数,没有任何明显的结果。我收到的错误是这条可爱的消息,绝对不以任何方式、形状或形式神秘:

[CLOSED] IMAP connection broken (server response)

此外,我还收到这些通知:

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 这似乎是一个有点麻烦的修复。

有什么想法吗?

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 "[email protected]"', SE_UID);

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

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

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

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.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷港 2024-11-10 12:08:40

我遇到了同样的问题,似乎正在生成错误,因为 Exchange 服务器通告了它不支持的身份验证协议(http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Exchange)。这个问题似乎只发生在 Linux 服务器上,因为我在 Windows 机器上使用完全相同的代码没有问题。这是一个长期存在的问题,PHP 最近进行了修补(v 5.3.2),以允许您禁用某些身份验证协议(http://php.net/manual/en/function.imap-open.php)。下面的代码对我来说间歇性地工作:

$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->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 攻击,但/关心

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

$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()));

    }    
}

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()));

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()));

    }    
}
难理解 2024-11-10 12:08:40

我有一个 PHP 脚本,它连接到 OWA 电子邮件服务器并使用 imap_open PHP 函数返回电子邮件的内容。然后,它使用该内容在 MindTouch 实例中创建一个页面。

所有这些代码都工作正常,但脚本报告了上面显示的 GSSAPI 失败错误。在我的 Web 结果页面中,(正确)报告了成功,但该页面还显示了 GSSAPI 错误消息。

我在代码中发现我打开了 error_reporting(E_ALL)。当我更改报告级别时,错误消息消失了。

我知道错误仍然存​​在,但我不知道为什么。但是,由于我的所有代码都工作正常,我只是希望错误消息消失,因为它让我的用户感到困惑。

将报告级别更改为较低级别即可解决此问题。

I have a PHP script that connects to an OWA email server and brings back the content of an email using the imap_open PHP function. Using that content, it then creates a page in a MindTouch instance.

All of this code works correctly, but the script was reporting the GSSAPI failure errors shown above. In my web results page, success was (correctly) reported, but the page also displayed the GSSAPI error messages.

What I discovered in my code was that I was turning on error_reporting(E_ALL). When I changed the reporting level, the error message went away.

I know that the error is still there, and I don't know why. But, since all of my code is working correctly, I just wanted the error message to go away, because it was confusing my users.

Changing the reporting level to a lower one took care of that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文