简体   繁体   中英

Email Piping - working but emails return errors

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 badih@badihbarakat.com local delivery failed

The following text was generated during the delivery attempt:

------ pipe to |/home/badihbar/public_html/handEmlTst.php generated by badih@badihbarakat.com ------

/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

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... :)

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

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