简体   繁体   English

PHP IMAP函数的解决方法? 尝试使用XAMPP在本地主机上处理传入电子邮件

[英]Workaround for PHP IMAP functions? Trying to work with incoming email on localhost using XAMPP

In the project I am working on right now, I am trying to add the functionality where I can change the status of a ticket from 'closed' to 'reopened' when the user sends an email to the support desk. 在我现在正在处理的项目中,我试图添加功能,以便当用户向支持台发送电子邮件时,可以将故障单的状态从“关闭”更改为“重新打开”。 I would also like to save their email reply to the database. 我也想将他们的电子邮件回复保存到数据库。

The problem I am running into is that I cannot get PHP's IMAP functions to work on my current Apache configuration. 我遇到的问题是我无法使PHP的IMAP函数在我当前的Apache配置上工作。 From looking at quite a few posts here at stackoverflow and other places, it seems that the problem is OpenSSL is not enabled in the standard configuration. 从stackoverflow和其他地方的大量文章中可以看出,问题在于标准配置中未启用OpenSSL。 So for example, when I run this code: 因此,例如,当我运行以下代码时:

<h1>IMAP testing!</h1>
<?php
$connect = "{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX";
$user    = "my email address @gmail.com";
$pass    = "my password";

$mailbox = imap_open($connect, $user, $pass);
?>

I get the error: 我得到错误:

Can't open mailbox {imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX: invalid remote specification.

Is there anything I can do, short of recompiling PHP, to mimic IMAP functionality on my local machine to be able to continue developing the functionality of working with email (email piping)? 除了重新编译PHP,我还能做些什么来模仿本地计算机上的IMAP功能,以便能够继续开发使用电子邮件(电子邮件管道)的功能?

Some notes on my current configuration, just in case it helps: 关于当前配置的一些注意事项,以防万一:

  • OS X 10.7.4 OS X 10.7.4
  • PHP v.5.3.1 PHP v.5.3.1

UPDATE - 更新-

I am almost there (thanks to dAm2K)! 我快到了(感谢dAm2K)!

I installed Stunnel (using Mac Ports), got everything configured finally and ran the command: 我安装了Stunnel(使用Mac端口),最后进行了所有配置,并运行了以下命令:

sudo stunnel /opt/local/etc/stunnel/stunnel.conf -c -d 127.0.0.1:443 -r imap.gmail.com:993

(For whatever reason I had to add the path to the .conf file) (无论出于何种原因,我都必须将路径添加到.conf文件中)

Now my code looks like this: 现在我的代码如下:

<?php
$connect = "{localhost:443}INBOX";
$user    = "my email address @gmail.com";
$pass    = "my password";

$mailbox = imap_open($connect, $user, $pass);
?>

Now when I load the page, it just hangs for 30 seconds or so and gives the warning: 现在,当我加载页面时,它只挂了30秒钟左右并发出警告:

Notice: Unknown: Connection failed to localhost,443: Operation timed out (errflg=2) in Unknown on line 0

What is interesting is that if I change $connect to: 有趣的是,如果我将$ connect更改为:

$connect = "{localhost:443/ssl}INBOX";

or 要么

$connect = "{localhost:443/novalidate-cert}INBOX";

I get the original error, which was: 我得到原始错误,它是:

Notice: Unknown: Can't open mailbox {localhost:443/novalidate-cert}INBOX: invalid remote specification (errflg=2) in Unknown on line 0

Any ideas? 有任何想法吗? Just a guess but could it maybe be something to do with the setup of stunnel, like having a self-signed cert or something with the stunnel.conf file I am missing? 只是一个猜测,但这可能与stunnel的设置有关,例如具有自签名证书或与我缺少的stunnel.conf文件有关吗?

Thanks a lot. 非常感谢。

Tim 蒂姆

You probably have a firewall that blocks outgoing TCP packets going to imap.gmail.com on port 993. 您可能有一个防火墙,该防火墙阻止了端口993上前往imap.gmail.com的传出TCP数据包。

Ask your sysadmin to check for outgoing TCP on dport 993 (imaps). 请您的系统管理员检查dport 993上的传出TCP(imaps)。 Also check if your DNS is resolving imap.gmail.com: 还要检查您的DNS是否解析imap.gmail.com:

The command: 命令:

telnet imap.gmail.com 993

should give you a valid connection. 应该给您有效的连接。 If it doesn't succeed you found the problem. 如果未成功,则说明存在问题。

You may want to install a IMAP server on your development machine so to continue the development offline... you can install "courier imap" package but it's not a very simple task... 您可能要在开发计算机上安装IMAP服务器,以便继续进行脱机开发...您可以安装“ courier imap”软件包,但这不是一个非常简单的任务...

If the connection succeded and the command: 如果连接成功并且命令:

openssl s_client -connect imap.gmail.com:993

give you a valid connection, the problem could be that your libc-client doesn't have SSL support compiled in. In this case you cannot use imaps with PHP, and you could use the "stunnel" command to forward clear traffic originating on your local machine going encrypted to gmail IMAP servers. 为您提供有效的连接,问题可能出在您的libc-client中没有编译SSL支持。在这种情况下,您不能将imaps与PHP一起使用,并且可以使用“ stunnel”命令来转发源自您的清除流量本地计算机将加密到gmail IMAP服务器。

The command: 命令:

stunnel -c -d 127.0.0.1:443 -r imap.gmail.com:993

should do the trick. 应该可以。 This way you can connect your PHP script to 127.0.0.1:443: 这样,您就可以将PHP脚本连接到127.0.0.1:443:

<?
  $connect = "{localhost:443}INBOX";
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM