Email piping to php. Could not open input file

Operating system: Ubuntu
OS version: 18.04

I’m trying to setup an email pipe so if someone sends an email to a particular address, a support ticket is created. I’m getting an error here when I send the email, I get bounce email back with error

Command died with status 1: "php
    /home/domain/public_html/inc/ticket-receiver.php". Command output: Could
    not open input file: /home/domain/public_html/inc/ticket-receiver.php

I’ve read many related thread on this but none helped me out. Here’s how I have setup my email piping. I have created an alias ticket-receiver@domain.com, in Advance tab I selected “Feed to Program” and the command I entered is

php /home/domain/public_html/inc/ticket-receiver.php
also tried
/user/bin/php /home/domain/public_html/inc/ticket-receiver.php

The php file for now just contains the following code which is not executing:

<?php
require __DIR__.'/config.php';

$stdin = fopen('php://stdin', 'r');

$temp = '';
while($line = fgets($stdin)) {
  $temp .= $line;
}
writeToLog($temp); //writes a string into a particular file

The permissions on the folders are

domain  750
    public_html  750
        inc  755
            ticket-receiver.php   644

I read somewhere about giving all folders upto my file 755 permissions, I don’t want to use that solution even if it works.

I also read about setting it up within the Usermin of the email that you want to use but I didn’t find the option that was mentioned in the steps by Steve.

Any suggestions?

Anyone? Please help me out. I’m out of ideas at this point.

Update: I’ve moved the file into /home/domain/ directory and I removed the require function as it was giving me permission denied error. This is how the file looks now

#!/usr/bin/php
<?php
$host = "localhost";
$database = "redacted";
$username = "redacted";
$password = "redacted";

$connect = mysqli_connect($host, $username, $password, $database);
if($connect != true){
	echo "Could not connect to Database. Aborting.";
	exit();
}

$stdin = fopen('php://stdin', 'r');

$temp = '';
while($line = fgets($stdin)) {
  $temp .= $line;
}
mysqli_query($connect, "INSERT INTO log (payload) VALUES ('$temp')");

Still getting the same error.

After a lot of digging I’m pretty sure Postfix is the one who needs permission to execute my file. Perhaps this answer will solve my problem if I’m able to understand it but should I mess with the config file? Shouldn’t virtualmin handle all this?

@Ilia Could you help me figure this out?

I wish I knew exactly what’s going on but I don’t. :slightly_smiling_face:

I can only think about one reason why this could be failing, which is line endings.

Try:

apt-get -y install dos2unix
dos2unix /home/domain/public_html/inc/ticket-receiver.php

No thats not the issue. It has to do something with the postfix configuration for virtualmin servers. It needs the proper configuration for aliases and db but I lack any functioning knowledge there myself. I was expecting virtualmin to make all the configuration changes automatically but its not.

Maybe someone from your team knows this stuff? All similar posts in the forums are 10 years old.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.