简体   繁体   中英

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 . 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. I'm using procmail as my MDA.

Here is my fetcmailrc file

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. You can see at the bottom I'm trying to pipe the email to a PHP script.

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. My fetchmail.log says:

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. 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. I'm no Fetchmail expert but the mda line looks fishy -- you hardly want two conflicting -d flags at the very least. Maybe that's the problem right there. The path to the .procmailrc will be deduced by Procmail with the -d option. 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. In my experience, attempting to use csh or tcsh with Procmail simply doesn't work. (Anyway, read Csh Programming Considered Harmful .) If you know exactly what you are doing, please explain why you have it there. Otherwise, take it out before you do anything else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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