PHP如何从php:// input读取EMAIL?

问题描述 投票:0回答:1

使用pipe.php,它将管道式电子邮件转换为Peter Rotich(osTicket)的票证。如它所说:/ *阅读来自STDIN的消息* /。电子邮件是由Virtualmin中的电子邮件转发器转发到此脚本的,因此这里是男生和女友的标准配置。

我想在继续正常过程之前拦截此STDIN并阅读电子邮件。

我尝试过:

$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 10024);
}
fclose($fd);

这可以正常工作,我可以阅读电子邮件,但是,这会破坏输入,并且无法通过以下正常过程进一步读取:

require_once(INCLUDE_DIR.'api.tickets.php');
PipeApiController::process();

我不想深入研究PipeApiController。我只想截取电子邮件并阅读一些内容。不幸的是,也没有简单的方法向PipeApiController询问电子邮件内容。

所以我想我必须先阅读电子邮件,然后将其通过发现的方式发送回去。这是完整的脚本:

/* Read STDIN into variable */
// $fd = fopen("php://stdin", "r"); //This creates problems 
$fd = fopen("php://input", "r"); //THIS IS OK
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 10024);
}
fclose($fd);

/* Saves the data into a file */
$fdw = fopen("/home/myhome/public_html/support/api/pipemail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);

/* Pass on the email for processing */
// $fdw = fopen("php://stdin", "w"); //This creates problems
$fdw = fopen("php://input", "w"); //THIS IS OK
fwrite($fdw, $email);
require_once(INCLUDE_DIR.'api.tickets.php');
PipeApiController::process();
fclose($fdw);

在读取和写入php:// stdin时,我从PipeApiController收到电子邮件解析错误,因此我将其更改为php:// input,它可以正常工作!但是现在我的pipemail.txt是空白!

所以我的问题是:

  1. 我可以将php:// input的内容中继到PipeApiController。
  2. 现在的问题是,由于我无法读取php:// input的内容,从php:// stdin更改了它以进行中继。

有什么想法吗?

PS。自从首次发布以来,这个问题已经稍有变化,因此我正在更改名称以使其匹配,现在也许有一个简单的答案。道歉。

php pipe stdout stdin
1个回答
0
投票

在PHP中,如果以后需要使用临时文件,请不要使用fclose(),因为此函数会删除临时文件。换句话说,省略该行:

FCLOSE($ FD);

© www.soinside.com 2019 - 2024. All rights reserved.