[英]Email piping with php script
Hi' I want to forward all the emails(which are come to my inbox) to php script and retrieve email content and save it in a file.嗨,我想将所有电子邮件(进入我的收件箱)转发到 php 脚本并检索电子邮件内容并将其保存在文件中。 So do that I was add email forwarder with piping path correctly.所以我正确地添加了带有管道路径的电子邮件转发器。
Address to Forward :tickets@ana.stage.centuryware.org转发地址:tickets@ana.stage.seasonware.org
Pipe to a Program : /home/centuryw/public_html/stage/ana/osticket/upload/api/pipe.php管道到程序:/home/ Centuryw/public_html/stage/ana/osticket/upload/api/pipe.php
I have used following script as pipe.php我使用以下脚本作为 pipe.php
#!/usr/bin/php –q
<?
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */
But there was no output file and all email are bounced to my inbox again.但是没有输出文件,所有电子邮件都再次退回到我的收件箱。 Can anyone help me please?有人可以帮我吗?
确保PHP文件设置了执行位(即chmod +x pipe.php
)。
I know this question is 2 years old but hopefully this will help anybody who stumbles across it as I did. 我知道这个问题是2岁,但希望这会帮助任何像我一样偶然发现它的人。
I had exactly the same issue and I spent ages trying to log errors etc. I then noticed that my script (and this one) had PHP short tags (ie <?
) and my PHP config file had these turned off. 我有完全相同的问题,我花了很多时间尝试记录错误等。然后我注意到我的脚本(和这个)有PHP短标签(即<?
)和我的PHP配置文件已关闭这些。 I changed the tag to <?php
and the script worked! 我将标签更改为<?php
并且脚本有效! Obvious but easy to miss... 明显但容易错过......
try the following 2 options to check: 尝试以下2个选项进行检查:
First, your php file must need to have execute permission(from owner group at least), otherwise it won't work. 首先,你的php文件必须具有执行权限(至少来自所有者组),否则它将无法工作。
What did you used when you were using forwarder? 你在使用货运代理时用过什么? You need to mention php compiler path at the beginnig also. 你还需要在beginnig上提到php编译器路径。
I have recently written an article regarding the full detail process of piping email content to php program , you will may like to have a look. 我最近写了一篇关于管理电子邮件内容到php程序的详细过程的文章,你可能想看看。 Let me know if you have any more question. 如果您有任何疑问,请告诉我。 Thanks. 谢谢。
I encountered the same problem.我遇到了同样的问题。 However I solved it by specifying the output file with full path name.但是我通过指定具有完整路径名的输出文件来解决它。 Instead of just 'mail.text', i entered '/home/username/public_html/mail.txt'.我输入的不是“mail.text”,而是“/home/username/public_html/mail.txt”。
Chanaka - Chanaka -
This doesn't address why there is no output file, but... 这没有解决为什么没有输出文件,但......
Don't you want to use a+
in your fopen()
call? 你不想在fopen()
调用中使用a+
吗? The w+
argument will delete any content that already exists in your output file. w+
参数将删除输出文件中已存在的任何内容。
PS: Have you tried doing a simple test which writes to the output file using dummy text (not the input from an e-mail) as the contents? PS:您是否尝试过使用虚拟文本(而不是电子邮件的输入)作为内容写入输出文件的简单测试?
Jeff Cohan 杰夫科恩
If this is actually an email box, why not use IMAP (PHP) ? 如果这实际上是一个电子邮箱,为什么不使用IMAP(PHP) ? There are lots of classes to read the mail with imap @ phpclasses.org 有很多课程可以用imap @ phpclasses.org阅读邮件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.