Home > other >  E-mail piping with e-mail forwarder does not work
E-mail piping with e-mail forwarder does not work

Time:04-08

I have a simple email pipe script. But I need a copy of the incoming e-mail going to another e-mail address. Unfortunately I do not receive the e-mail as I wanted.

The code;

#!/usr/bin/php -q
<?php
$email_msg = ''; // the content of the email that is being piped
$email_addr = '[email protected]'; // where the email will be sent
$subject = 'Piped:'; // the subject of the email being sent
// open a handle to the email
$fh = fopen("php://stdin", "r");
// read through the email until the end
while (!feof($fh)){
    $email_msg .= fread($fh, 1024);
}
fclose($fh);
// send a copy of the email to your account
mail($email_addr, $subject, "Piped Email: ".$email_msg);
?>

CodePudding user response:

Your mail server logs will probably say something about this. My guess is that it might be failing because your message is malformed because of the prefix you're adding. Try sending the message untouched, like this:

mail($email_addr, $subject, $email_msg);

Separately, for simple forwarding like this, you can probably set up your mail server to do this directly without having to go via a script.

CodePudding user response:

There is no error checking in your script. There is no instrumentation in your script to see if it is even being run. You have not said why you believe that the script is being triggered. You have not said how mail() works on your test site.

Decompose the issues. Replace this script with one which dumps stein to a file to find out if there is an issue with the input integration.

Write and run a script which sends an email when using mail() when manually invoked. If you control the MTA then read your logs - even if these experiments are successful.

Then go back to your original script. Add some logging. Check the value returned by mail(). Check that the delivery path accepts forwarded mail with a broken envelope.

  • Related