7

I've installed sendmail and want to pipe incoming emails to php.

Every time I send an email to my server I am getting an email back with an error message:

could not open input file: /root/fw/catcher.php 554 5.3.0 unknown mailer error 1

I think something with the permissions of catcher.php is wrong but I couldn't figure it out by myself.

Sendmail is installed and I have added an alias:

root: "|/usr/bin/php /root/fw/catcher.php"

Permissions (after chmod 777; I tried chmod 777 and chmod 755 but both won't work):

drwxrwxrwx 2 root root 4096 Jul 20 14:27 fw
-rwxrwxrwx 1 root root   45 Jul 20 14:27 catcher.php

catcher.php (converted line endings to Unix style):

#!/usr/bin/php
<?php echo 'Test'; exit(0); ?>

Executing my php file over cli works fine. All of these commands work:

/usr/bin/php /root/fw/catcher.php
/usr/bin/php7.3 /root/fw/catcher.php
php /root/fw/catcher.php
php7.3 /root/fw/catcher.php

I think there is a problem with the permissions of sendmail.

3
  • First i would suggest you use a shell script and pass the php file name in that. See this serverfault.com/questions/261191/… and musicalgeometry.com/p/1473 Commented Jul 22, 2019 at 17:29
  • any update on this? Commented Jul 25, 2019 at 14:44
  • What is reported in the log file? Commented Jul 26, 2019 at 23:33

2 Answers 2

1
+100

The error "could not open input file" means that the file cannot be read for some reason.

Please follow these steps to check:

  1. converted line endings to Unix style

I do not know how you check this, but you could try to redo this using dos2unix, as described in this link

dos2unix catcher.php > newcatcher.php

and then compare file sizes.

  1. it could be that BOM breaks the script, as described here, the shebang line "#!/usr/bin/php" tells the system which interpreter needs to be run when invoking such a script.

If the script is encoded in UTF-8, one may be tempted to include a BOM at the beginning. But actually the "#!" characters are not just characters. They are in fact a magic number that happens to be composed out of two ASCII characters. If you put something (like a BOM) before those characters, then the file will look like it had a different magic number and that can lead to problems.

The script will run over cli because you specifically tell it which intepreter to use: php or php7.3:

php /root/fw/catcher.php
php7.3 /root/fw/catcher.php

To remove BOM from the start of the file, try this:

dos2unix catcher.php

Try to run /root/fw/catcher.php, as a shell script without using php or php7.3 executable. From terminal, run:

./root/fw/catcher.php
Sign up to request clarification or add additional context in comments.

Comments

0

Have you checked whether SELinux is enabled and enforcing? You can see this with the getenforce command.

If this returns Enforcing, you can fix this in a few ways. You can either disable SELinux enforcement with setenforce Permissive, or create a policy that allows Apache to run sendmail.

To create a policy like this, the easiest way is to use the audit2allow tool, which is part of the policycoreutils-python - so install that if audit2allow isn't available. Then, check /var/log/audit.log to see if there are errors about sendmail not being able to run. These error lines can be piped to audit2allow to create a policy file that can be enabled with semodule -i <module.pp>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.