如何将 Imap 连接从 PHP Imap 库从 PHP/JQuery 传递到 PHP 文件

发布于 2024-10-30 14:47:53 字数 1010 浏览 4 评论 0原文

我希望能够使用 Jquery 将名为 $connection 的 Imap 文件从 1 个 php 文件传递​​到另一个 php 文件。问题是,它不会作为对象传递,而是转换为名为资源的字符串 #54 - 有没有可能的方法将 Imap Connection 对象传递到另一个 PHP 文件?我确实需要保持此连接打开,因为如果我反复关闭它并打开新连接,Hotmail 和 Yahoo 等提供商会将我们锁定 15-30 分钟。

这是我当前的代码 Jquery w/ PHP 变量混合:

    var dataString='server=<?php echo $server; ?>&email=<?php echo $email_address; ?>&connection=<?php echo $connection; ?>&password=<?php echo $password; ?>&server=<?php echo $server;?>&daysago='+daysago+'&num='+num;
    $.ajax({
       type: "POST",
    url: "fastsearch.php",
    data: dataString,
    success: function(msg){

Is it possible or conceivable to pass this variable to a php file using jquery or other other than jquery?如果没有,我有哪些解决方法?是否可以在不结束 PHP 文件的情况下显示结果?

这是有关 imap_open 和 imap_open 的更多信息imap 流对象:

http://www.php.net/manual/ en/function.imap-open.php

I would like to be able to pass a an Imap file named $connection from 1 php file to another php file using Jquery. The issue is, It doesn't pass as the object, it gets converted to a string called resource #54 - Is there any possible way to pass the Imap Connection object to another PHP file? I really need to keep this connection open because if I repeatedly close it and open new connections, providers such as Hotmail and Yahoo lock us out for 15-30 minutes.

Here's my current code Jquery w/ PHP variables mixed in:

    var dataString='server=<?php echo $server; ?>&email=<?php echo $email_address; ?>&connection=<?php echo $connection; ?>&password=<?php echo $password; ?>&server=<?php echo $server;?>&daysago='+daysago+'&num='+num;
    $.ajax({
       type: "POST",
    url: "fastsearch.php",
    data: dataString,
    success: function(msg){

Is it possible or conceivable to pass this variable to a php file using jquery or something other than jquery? If not, what are my options for a workaround? Is it possible to display results without ending a PHP file?

Here's more info on imap_open & the imap stream object:

http://www.php.net/manual/en/function.imap-open.php

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

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

发布评论

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

评论(2

喵星人汪星人 2024-11-06 14:47:53

您无法在脚本之间“传递”连接,因为它们是在单独的服务器进程下生成的,因此在完成后没有对其的引用。您需要做的是使用 pfsockopen< 打开与 imap 服务器的持久连接/a>:

$f = pfsockopen('an.imap_server.com', 143)

然后,您将手动构建基本的 imap 命令并使用 fputs 发送到打开的连接:

$query = 'LOGIN ' . strlen($user) . "}\r\n" . $user ... 
fputs($f, $query)

等等。

You cannot "pass" a connection between scripts as they are spawned under seperate server processes so after it completes there is no reference to it. What you need to do is open up a persistent connection to the imap server using pfsockopen:

$f = pfsockopen('an.imap_server.com', 143)

You will then construct the essential imap commands by hand and use fputs to post to the open connection:

$query = 'LOGIN ' . strlen($user) . "}\r\n" . $user ... 
fputs($f, $query)

and so on.

故事和酒 2024-11-06 14:47:53

您无法在不同的 PHP 脚本实例之间传递资源。

韦斯的答案是正确的 - 但请阅读讨论。

如果是我,我会使用守护进程/计划作业来获取邮件 - 虽然您可以用 PHP 编写自己的邮件,但我只会使用 fetchmail 和 cron 从远程系统获取电子邮件,然后将其镜像到本地邮箱或通过 procmail 提供。

You can't pass resources between separate instances of PHP scripts.

The answer by Wes is sort of correct - but do read the discussion.

If it were me I'd use a daemon/scheduled job to fetch the mail - while you could write your own in PHP, I'd just use fetchmail and cron to get the email off the remote system then either mirror it in a local mailbox or feed it through procmail.

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