Search code examples
phpemailpipeemail-processing

How to Change the MTA return error if something happend when delivery email failed using pipe to php script method


I using WHM/Cpanel

Im using the pipe technique to forward the income emails to php script and everthing fine. but while working if any error happend while piping the following msg for example will returned to the email sender

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/someuser/public_htmk/pipe.php
  generated by support@somecompany.net
  local delivery failed

Please note that I make the pipe from Cpanel for the email support@somecompany.net|/home/someuser/public_htmk/pipe.php

the php script below does not have error :) but I define the path of the file to make an error because it should be public_html not public_htmk but I make this error to show you the error message which returned to the email sender.

So is there anyway to control of this returned message or disable it . for example change it or not to send the physical address of the php file that we are running to pipe the email atleast?

BTW I'm using

WHM/Cpanel Dovecot PHP

and this is a sample of the pipe script (this script does not have any error)

#!/usr/local/bin/php -q
<?php   

// read from stdin
$emg_stdf = fopen("php://stdin", "r");
$email = "";
while (!feof($emg_stdf))
{
    $emg_orgemailmsg .= fread($emg_stdf, 1024);
}
fclose($emg_stdf);

mail('me@example.org','From my email pipe!','"' . $emg_orgemailmsg . '"');

I'm looking to customize or disable the return msg which returned to the email sender when some error happened when piping email to a script.

any ideas?


Solution

  • If you do not insist on putting troublesome code in the pipe definition, you can use the shell script wrapper around your php script, something like

    #!/bin/bash
    /home/someuser/public_htmk/pipe.php >&/home/someuser/pipe.errors.log || true
    

    and use it in your pipe definition.