PHP IMAP功能的解决方法?尝试使用XAMPP在localhost上使用传入的电子邮件 [英] Workaround for PHP IMAP functions? Trying to work with incoming email on localhost using XAMPP

查看:377
本文介绍了PHP IMAP功能的解决方法?尝试使用XAMPP在localhost上使用传入的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我正在进行的项目中,我正在尝试添加功能,当用户向支持台发送电子邮件时,我可以将门票的状态从已关闭更改为重新打开状态。我还想保存他们的电子邮件回复数据库。



我遇到的问题是我无法让PHP的IMAP功能在我目前的Apache配置下工作。从stackoverflow和其他地方看这些相当多的帖子,似乎问题是OpenSSL在标准配置中未启用。所以例如,当我运行这个代码:

 < h1> IMAP测试!< / h1> 
<?php
$ connect ={imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX;
$ user =我的电子邮件地址@ gmail.com;
$ pass =我的密码;

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

我收到错误:

 无法打开邮箱{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX:无效的远程规范。 

有没有什么可以做的,没有重新编译PHP,以模仿我的本地机器上的IMAP功能能够继续开发使用电子邮件(电子邮件管道)的功能?



有关我当前配置的一些注意事项,以防万一有帮助:




  • OS X 10.7.4

  • PHP v.5.3.1



更新 -



我几乎在那里(感谢dAm2K)!



我安装了Stunnel(使用Mac端口),最后配置了所有配置,并运行命令:

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

(无论何种原因,我必须添加.conf文件的路径)



现在我的代码如下:

 <?php 
$ connect ={localhost:443} INBOX;
$ user =我的电子邮件地址@ gmail.com;
$ pass =我的密码;

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

现在加载页面时,它只会挂起30秒左右,并发出警告: / p>

 注意:未知:连接失败到localhost,443:操作超时(errflg = 2)in Unknown 0行$ b $有趣的是,如果我将$ connect更改为:



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

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

我收到原始错误,即:



注意:未知:无法打开邮箱{localhost:443 / novalidate-cert} INBOX:无效远程规范(errflg = 2)in Unknown 0行$ 0

任何想法?只是一个猜测,但是这可能与stunnel的设置有关,比如拥有一个自签名证书或者与stunnel.conf文件中的某些东西丢失?



非常感谢。



Tim

解决方案

你可能有一个防火墙阻止在993端口上传出的TCP数据包到imap.gmail.com。



请求您的sysadmin在dport 993(imaps)上检查传出的TCP。
还要检查你的DNS是否解决imap.gmail.com:



命令:

  telnet imap.gmail.com 993 

应该给你一个有效的连接。如果没有成功,您会发现问题。



您可能希望在开发机器上安装IMAP服务器,以便继续开发离线...您可以安装快递imap包,但它不是一个非常简单的任务...



如果连接成功并且命令:

  openssl s_client -connect imap.gmail.com:993 

给你一个有效的连接,问题可能是您的libc客户端没有编译SSL支持。在这种情况下,您不能使用PHP进行imaps,您可以使用stunnel命令转发明确的流量在您的本地机器上加密到Gmail IMAP服务器。



命令:

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



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


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. 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. 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)?

Some notes on my current configuration, just in case it helps:

  • OS X 10.7.4
  • PHP v.5.3.1

UPDATE -

I am almost there (thanks to dAm2K)!

I installed Stunnel (using Mac Ports), got everything configured finally and ran the command:

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)

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:

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 = "{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?

Thanks a lot.

Tim

解决方案

You probably have a firewall that blocks outgoing TCP packets going to imap.gmail.com on port 993.

Ask your sysadmin to check for outgoing TCP on dport 993 (imaps). Also check if your DNS is resolving 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...

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.

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:

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

这篇关于PHP IMAP功能的解决方法?尝试使用XAMPP在localhost上使用传入的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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