E-Mail Piping Woes

software development


Before I get started just wanted to say any help is greatly appreciated!

I’m trying to get e-mail piping to work so that I can process attachments with PHP. Specifically, I’m sending images to a specific email address and based on who it came from, store the image into a specific folder.

Steps I’ve taken thus far are:

  1. Set up shell access for a particular user
  2. Have e-mail address that forwards to the above shell user.
  3. Set up a filter so that any email that hits the email address in 2) with a subject that contains the word “Picture” is forwarded to the shell account.

After doing those three steps I set up a .forward.postfix file in my home directory for that user which has:

In order to test this I simply have the script email my personal e-mail once the script is ran. However, I’m not getting anything sent to my email…

Is there anything I’m doing wrong or a way I can confirm that the emails are forwarding? Like I said, any help is greatly appreciated!


Login to shell and test it by piping a text file (example message) to the script:

/usr/local/bin/php /home/SHELLACCOUNTUSERNAME/php/picture_inbound.php < test.txt

Also keep in mind the PHP version, 5.3 is probably at /usr/local/bin/php-5.3 on your machine.

Have you tried making the script executable using chmod and prepending a shebang line?


Thanks for the response! To answer your questions and suggestions…

-Using shell I typed ‘which php’ and that gave me the /usr/blocal/bin/php. Should I change to what you noted above anyway? Using my phpini file it seems I am running php version 5.2.17.

-I enabled file permissions on the php script through my FTP client to 777 for testing purposes. I initially tried “chmod a+x picture_inbound.php” while in that specific file’s directory but noticed when checking the file permissions in FTP that none of the options were set to execute so I figured it might be safer to switch back to 777.

-To try piping the test.txt file, would that have to reside in the same directory as picture_inbound.php? That seems like an excellent way for me to test the script and .forward.postfix file.

-By prepending shebang line do you mean something like this “#!/usr/local/bin/php” prior to the <?php bracket in the php script? I do have that particular line there.

Sorry for what are probably simply questions but, I’m really new at this.


The version of PHP you use depends on whether or not it supports your script.

Do NOT set permissions on scripts and programs to 777. That is insecure. Directories, scripts and programs should be 755. Data files should be 644 however if the file is not meant to be served over the web (library code or data files inside web directories) or not to be viewed by other users set the last number to 0.

The sample message does not have to be in the same directory as the PHP file. You would need to specify the path to the text file like you did for the PHP file.

If you prepend the shebang you can make the PHP file executable (ie 755) and not need to pass the filename to PHP as an argument. IIRC correctly PHP CLI should ignore it, but if you see it in the output then its not and that might be a problem.


I did as you suggested for file permissions and the test.txt file and the script seems to be working!!! (as I set up the script just to send me a simply email on execution. Which it did)

Which I believe leaves us with the issue being the .forward.postfix file or the actual filters I set up to forward emails to the shell account. Is there a way to set any email received by an address to forward to a shell account?

Once again thanks for the help!!!


A filter such as “to” “contains” with receiving email address should handle the “always” case.

I tend to like to make it obvious what I’m attempting tho, so that when I look at 2 years later I can quickly tell what my objective was, so in that case I would do something like: “Subject” “Does not contain” and then a random string like “hjhdjfhjsheunjdhfdjfhk” that a real subject would probably never contain.


That’s a great idea. I’ll add that and see if I can get working. [hr]
So I added the filter that anything not containing some random string in the subject would get forwarded to the shell account and it still didn’t work.

So I guess the last possible reason for this has to be the .forward.postfix file.[hr]
So I’m thinking about it and wondering if my .forward.postfix file is in the wrong location.


Got it!

Apparently the path I thought : /home/shelluser/php/picture_inbound.php
was actually : /home/shelluser/home/shelluser/php/picture_inbound.php

I was reaching my wits end and then remembered I’m logging into my FTP as just FTP and that I should probably double check the absolute path so I put “FILE” in the script and reran
/usr/local/bin/php picture_inbound.php < test.txt
while in the directory of the picture_inbound.php and it sent me the email with the absolute path.

Thanks everyone for your help! I really appreciate it.