简体   繁体   English

如何将电子邮件转发到PHP脚本?

[英]How to forward emails to PHP script?

I'm trying to figure out how I can forward (or pipe) an email to a PHP script using fetchmail . 我试图弄清楚如何使用fetchmail将电子邮件转发(或传递)到PHP脚本。 I've never done this and am not even sure if I'm on the right track. 我从来没有做过,甚至不确定自己是否走对了。 From what I've read I think I need to use an MDA to forward the mail. 从阅读的内容来看,我认为我需要使用MDA来转发邮件。 I'm using procmail as my MDA. 我正在使用procmail作为我的MDA。

Here is my fetcmailrc file 这是我的fetcmailrc文件

set daemon 150
set logfile /local/web/sites/sitename/mail/fetchmail.log
poll blahblah with proto IMAP
user Username there with password userpassword is Username here
ssl
fetchall
no rewrite
mda "/usr/bin/procmail -d Username -f %F -d %T $HOME/.procmailrc";

Here is my procmailrc file. 这是我的procmailrc文件。 You can see at the bottom I'm trying to pipe the email to a PHP script. 您可以在底部看到我正在尝试将电子邮件发送到PHP脚本。

SHELL=/bin/csh
DEFAULT=/var/mail/Username/ 
MAILDIR=/var/mail/Username/    

:0
! `/usr/local/bin/php -f /local/web/sites/stack/htdocs/bin/catchmail.php`

I run fetchmail and the fowarding (piping to PHP) doesn't work. 我运行fetchmail,而转发(向PHP配管)不起作用。 My fetchmail.log says: 我的fetchmail.log说:

procmail:  Insufficient prvileges
procmail:  Unknown user

Any pointers? 有指针吗? Am I even headed in the right direction? 我什至朝着正确的方向前进吗?

You are not piping to PHP, you are sending email to the address that your PHP script outputs. 您没有使用PHP,而是将电子邮件发送到PHP脚本输出的地址。 You probably want to change the exclamation mark ( ! ) to a pipe ( | ) in order for the recipe to do what you describe. 您可能希望将感叹号( ! )更改为管道( | ),以便配方执行您描述的操作。

The error message from Procmail indicates that you are invoking it incorrectly, or that it lacks a setuid bit or something like that. 来自Procmail的错误消息表明您正在错误地调用它,或者它缺少setuid位或类似的东西。 I'm no Fetchmail expert but the mda line looks fishy -- you hardly want two conflicting -d flags at the very least. 我不是Fetchmail专家,但mda行看起来像鱼一样-您几乎不需要两个冲突的-d标志。 Maybe that's the problem right there. 也许那就是问题所在。 The path to the .procmailrc will be deduced by Procmail with the -d option. .procmailrc的路径将由Procmail使用-d选项推导出。 Try with something simpler, like this: 尝试使用更简单的方法,例如:

mda "/usr/bin/procmail -f %F -d %T"

By the way, the assignment SHELL=/bin/csh seems really out of line. 顺便说一句,赋值SHELL=/bin/csh似乎与实际SHELL=/bin/csh In my experience, attempting to use csh or tcsh with Procmail simply doesn't work. 以我的经验,尝试在Procmail中使用cshtcsh根本行不通。 (Anyway, read Csh Programming Considered Harmful .) If you know exactly what you are doing, please explain why you have it there. (无论如何,请阅读《 Csh编程被认为有害》 。)如果您确切地知道自己在做什么,请解释为什么要在那里做。 Otherwise, take it out before you do anything else. 否则,请先将其取出,然后再执行其他操作。

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

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