简体   繁体   English

使用procmail调用php脚本

[英]Using procmail to call a php script

I am attempting to do some custom email forwarding. 我正在尝试做一些自定义电子邮件转发。 #1 I am on a shared server, which is using qmail, and optionally procmail. #1我在共享服务器上,它使用qmail,也可以使用procmail。

What I am trying to accomplish is some custom email forwarding of one address, based on a schedule. 我想要完成的是基于时间表的一个地址的一些自定义电子邮件转发。 For example, I have a schedule of employees that are working on each weekday, and I have a php script that selects a random employee's email address that is working today. 例如,我有一个工作日程表,每个工作日都在工作,我有一个PHP脚本,用于选择当前正在运行的随机员工的电子邮件地址。

So I'm trying to just call that script in procmail, and output the result(which is a single email address) on the forward line: 所以我试图在procmail中调用该脚本,并在前行输出结果(这是一个电子邮件地址):

Example: 例:

#Something
LOGFILE=/usr/home/myname/procmail-log
VERBOSE=yes
EXITCODE=99
MAILDIR=/usr/boxes/myname
DEFAULT=/usr/boxes/myname/mybox
SHELL=/bin/sh
MYVAR=$(php -q /usr/home/myname/testemail/emailtester.php)

:0
! $MYVAR

This is not working. 这不起作用。 At all. 完全没有。 I have also tried: 我也尝试过:

MYVAR=`php /usr/home/myname/testemail/emailtester.php`

as well as just piping it into the forward line: 以及将它输送到前线:

:0
! |php /usr/home/myname/testemail/emailtester.php

I am COMPLETELY out of my element here... I tried to not even use procmail, and I just piped the whole email over to a php script, from qmail. 我完全不在我的元素中...我试图甚至不使用procmail,我只是将整个电子邮件从qmail传送到php脚本。 I need the headers to stay intact, like a normal forward, and that proved to be difficult with PHP, and a little beyond my scope.( I managed to create an infinite email loop) So, I would rather not try that again. 我需要标题保持完整,就像正常的前进一样,并且用PHP证明是困难的,并且有点超出我的范围。(我设法创建了一个无限的电子邮件循环)所以,我宁愿不再尝试。

I could just try to script this in perl, which I have never used, but I need the schedule to be administerable from a web interface, or at least in a user friendly way. 我可以尝试在perl中编写脚本,这是我从未使用过的,但是我需要从Web界面管理日程安排,或者至少以用户友好的方式管理。

Any help, or suggestions would be appreciated at this point, thanks 任何帮助或建议都会在这一点上受到赞赏,谢谢

EDIT: 编辑:

Well, since I cant put code in a comment, I'll just edit here. 好吧,既然我不能把代码放在评论中,我只会在这里编辑。

Now getting this in my log: 现在在我的日志中得到这个:

Folder: /usr/local/bin/php /usr/home/idnani/testemail/emailtester.ph     1679
"rocmail: Executing "/usr/local/bin/php,/usr/home/idnani/testemail/emailtester.php
Could not open input file: /usr/home/idnani/testemail/emailtester.php

When I use with :0fw I get: 当我使用:0fw我得到:

"rocmail: Executing "/usr/local/bin/php,/usr/home/idnani/testemail/emailtester.php
Could not open input file: /usr/home/idnani/testemail/emailtester.php
procmail: [69907] Thu Jun 16 14:04:17 2011
procmail: Program failure (1) of "/usr/local/bin/php"
procmail: Rescue of unfiltered data succeeded

EDIT: Figured it out! 编辑:想出来!

Found the correct way after MUCH trial and error. 在多次试验和错误后找到正确的方法。

Don't even use the pipe at, all, and you do need the ! 甚至不要使用管道,所有,你确实需要! forward symbol: 前进符号:

Final Rule: 最终规则:

:0
! `/usr/local/bin/php -f $HOME/emailtest/emailtester.php`

So simple... I'm a little mad it took me hours to figure this out, thanks everyone for helping to point me in the right direction! 这么简单......我有点疯狂,花了我几个小时来弄清楚这一点,谢谢大家帮助指出我正确的方向!

You were so close... You need to pipe it without the ! 你是如此接近......你需要管它没有 ! forward: 向前:

:0
|/usr/bin/php /usr/home/myname/testemail/emailtester.php

EDIT I put in the full path to PHP, in case procmail's $PATH is incomplete. 编辑我把完整的PHP路径,以防procmail的$PATH不完整。 Change it to whatever your actual php path is. 将其更改为您的实际php路径。

To avoid email loops, I've done stuff like this: 为了避免电子邮件循环,我做了这样的事情:

PATH=/usr/local/bin:/bin:/usr/bin
MAILDIR=$HOME/Mail
DEFAULT=$HOME/Mail/inbox
LOGFILE=$HOME/procmail.`date +%Y-%m`.log
SHELL=/usr/bin/ksh

MY_XLOOP='X-Loop: emailtester.php'

:0
* ! ^$MY_XLOOP
{
    # add a header
    # 'f' = filter: continue processing results of program
    # 'w' = wait for program to return
    # 'h' = pass message headers to program
    :0fwh
    | formail -A "$MY_XLOOP"

    # then forward the message
    # 'c' = send a copy to recipient and continue processing
    :0c
    | php /usr/home/myname/testemail/emailtester.php
}

# if we get here, then the message has an X-Loop header.
# let it fall into $DEFAULT

Found the correct way after MUCH trial and error. 在多次试验和错误后找到正确的方法。

Don't even use the pipe at, all, and you do need the ! 甚至不要使用管道,所有,你确实需要! forward symbol: 前进符号:

all this rule does is ask the php script for a single email, and then forwards to that email. 所有这个规则都是向php脚本询问一封电子邮件,然后转发到该电子邮件。 Final Rule: 最终规则:

:0
! `/usr/local/bin/php -f $HOME/emailtest/emailtester.php`

So simple... I'm a little mad it took me hours to figure this out, thanks everyone for helping to point me in the right direction! 这么简单......我有点疯狂,花了我几个小时来弄清楚这一点,谢谢大家帮助指出我正确的方向!

Michael's answer looks like it should work, and maybe it does under a different circumstance? 迈克尔的回答看起来应该有效,也许它在不同情况下会有效? I couldn't get it to, which is why I am answering this myself.. 我无法理解,这就是为什么我自己回答这个问题。

New edit: 新编辑:

Note: You can still retrieve the whole email in php via STDIN 注意:您仍然可以通过STDIN在php中检索整个电子邮件

Note: you can put /usr/local/bin/php in your script itself like this on the first line: 注意:您可以在第一行中将/ usr / local / bin / php放在脚本本身中:

#!/usr/local/bin/php

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

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