使用procmail调用php脚本
我正在尝试进行一些自定义电子邮件转发。 #1 我在一个共享服务器上,它使用 qmail,也可以选择使用 procmail。
我想要完成的是根据时间表对一个地址进行一些自定义电子邮件转发。例如,我有一个每个工作日工作的员工的时间表,并且我有一个 php 脚本,它随机选择今天工作的员工的电子邮件地址。
所以我试图在 procmail 中调用该脚本,并在前一行输出结果(这是一个电子邮件地址):
示例:
#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
这不起作用。完全没有。我也尝试过:
MYVAR=`php /usr/home/myname/testemail/emailtester.php`
以及将其输送到前线:
:0
! |php /usr/home/myname/testemail/emailtester.php
我完全不适应这里...... 我什至尝试不使用 procmail,我只是将整个电子邮件从 qmail 传送到一个 php 脚本。我需要标头保持完整,就像普通的转发一样,事实证明这对 PHP 来说很困难,而且有点超出了我的范围。(我设法创建了一个无限的电子邮件循环)所以,我宁愿不再尝试。
我可以尝试用 perl 编写这个脚本,我从未使用过它,但我需要可以从 Web 界面管理时间表,或者至少以用户友好的方式管理。
此时,任何帮助或建议将不胜感激,谢谢
编辑:
好吧,由于我无法在评论中添加代码,所以我将在此处进行编辑。
现在将其记录在我的日志中:
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
当我使用 :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
编辑:弄清楚了!
经过多次尝试和错误后找到了正确的方法。
甚至根本不使用管道,而您确实需要!前进符号:
最终规则:
:0
! `/usr/local/bin/php -f $HOME/emailtest/emailtester.php`
如此简单...我有点生气,我花了几个小时才弄清楚这一点,感谢大家帮助我指出正确的方向!
I am attempting to do some custom email forwarding. #1 I am on a shared server, which is using qmail, and optionally 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.
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:
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. 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.
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.
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:
"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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你是如此接近...你需要通过管道不使用
!
转发:编辑我输入了PHP的完整路径,以防万一procmail 的
$PATH
不完整。将其更改为您实际的 php 路径。You were so close... You need to pipe it without the
!
forward:EDIT I put in the full path to PHP, in case procmail's
$PATH
is incomplete. Change it to whatever your actual php path is.经过多次尝试和错误后找到了正确的方法。
甚至根本不使用管道,而您确实需要!转发符号:
此规则所做的只是向 php 脚本询问一封电子邮件,然后转发到该电子邮件。
最终规则:
如此简单......我有点生气,我花了几个小时才弄清楚这一点,感谢大家帮助我指出正确的方向!
迈克尔的答案看起来应该有效,也许在不同的情况下也有效?我无法得到它,这就是为什么我自己回答这个问题。
新编辑:
注意:您仍然可以通过 STDIN 在 php 中检索整个电子邮件
注意:您可以将 /usr/local/bin/php 放入脚本中本身就是这样
第一行:
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.
Final Rule:
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
Note: you can put /usr/local/bin/php in your script itself like this
on the first line:
为了避免电子邮件循环,我做了这样的事情:
To avoid email loops, I've done stuff like this: