0
votes

I have setup my email forwarding to "Pipe to a program". The piping seems to be working because when an email is sent to my piped email address it returns an undelivered message with errors from my PHP script such as:

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed:

pipe to |/home/badihbar/public_html/handEmlTst.php generated by [email protected] local delivery failed

The following text was generated during the delivery attempt:

------ pipe to |/home/badihbar/public_html/handEmlTst.php generated by [email protected] ------

/home/badihbar/public_html/handEmlTst.php: line 1: ?php: No such file or directory /home/badihbar/public_html/handEmlTst.php: line 3: //: is a directory /home/badihbar/public_html/handEmlTst.php: line 4: //: is a directory /home/badihbar/public_html/handEmlTst.php: line 5: syntax error near unexpected token (' /home/badihbar/public_html/handEmlTst.php: line 5: // date_default_timezone_set("Asia/Muscat");'

------ This is a copy of the message, including all the headers. ------

Apparently, for some reason, it is not recognizing the php file to have php scripts. What I'm suspecting is the first line itself. How can I know what path should i put after the "#!" ?

My php script from handEmlTst.php:

#!/usr/lib/php -q
<?php

// include_once "Libraries/connection.class.php";
// include_once "includes/readini.inc.php";
// date_default_timezone_set("Asia/Muscat");

$starttime = date("h:i:s");

// create the connection object...
$s = ini_get("mysql.default_host");

$conn = mysql_connect($s,'badihbar_badih','letmein2013');

$db = "badihbar_supportcenter";

$attachments = array();

if(mysql_error())
{
    print "Error Occured: ".mysql_error()."<br>";
    $err = true;
}

mysql_select_db($db,$conn);

$commString  = "INSERT INTO scriptEmails (Message) VALUES ('From the Script - ".$starttime."')";

// , '".mysql_real_escape_string($email)."'

$result = mysql_query($commString, $conn);
if(mysql_error())
{
    // echo "Error Occured Saving Data: ".mysql_error()."<br>";
    // print $Conn->commString."<br>";
}


?>

I have checked phpinfo() for the path but honestly didn't know what I'm looking for. So, I supposed that the php interpreter would be in usr/lib/ or something. Should I substitute usr with my domain user or something? I appreciate if anybody can advise in this regard.

many Thanks

2
After adjusting the first line to #!usr/bin/php -q, I am getting the following in the bouncing undelivered mail message:Badih Barakat
it will be usually /usr/bin/php try this whereis php or which php to find out the pathArun Kumar
Error in argument 1, char 3: option not found Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>] php <file> [args...] -a Run interactively -b <address:port>|<port> Bind Path for external FASTCGI Server mode -C Do not chdir to the script's directory -c <path>|<file> Look for php.ini file in this directory -n No php.ini file will be used -d foo[=bar] Define INI entry foo with value 'bar'Badih Barakat
dear Arun, usr/bin/php seems to be correct... but it is giving some argument error... check my second comment for the first few lines of the returned error...Badih Barakat
remove the argument and try just #!/usr/bin/phpArun Kumar

2 Answers

4
votes

I managed to get it working after all. Below are the steps for all to benefit... :)

  1. I used phpinfo() to get the path for the php interpreter. I used the "Configuration File (php.ini) Path" parameter value which was usr/lib/ for my server.
  2. used #!/usr/lib/php -q as the first most line in my handling script.
  3. This part was the issue in my case. UPLOAD THE FILE AS ASCII, NOT BINARY!
  4. Made sure the chmod of the uploaded file was 755.
  5. Set the forwarding of my email address to "Pipe to a program" in my cpanel and put the path of the php script file I've uploaded.

That's did it. As I mentioned, my problem was with the file being uploaded by the FTP application as binary instead of ASCII.

Thanks, all... :)

-1
votes

You can also use #!/usr/local/bin/php at the starting line on your PHP file, which is the cli binary instead of the cgi binary.

This works for me, If you Passed above case as said by @Badih Barakat