PHP email piping formatting issue

  • Thread starter Deleted member 878571
  • Start date
D

Deleted member 878571

Guest
I've set up an email forwarder in cPanel which pipes any incoming email to pipe.php. The email then gets forwarded to a different email ([email protected] for example) via pipe.php. In the future, I'll have DB calls determining where the email should be forwarded to, based on the sender etc...

But at the moment I'm just trying to set up the forwarder properly.

PHP:
#!/usr/bin/php -q

<?php

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

$message = "";

while ( !feof( $fd ) )
{
   $message .= fread( $fd, 1024 );
}

fclose( $fd );

mail('[email protected]','New message!',$message)

?>
The email forwards to me just fine, however I'm experiencing two issues I'm hoping someone could help me out with:

  1. The $message appears in plain text with all of the MIME stuff - so the email just looks like jibberish to the average user.
  2. Although the email gets forwarded just fine, the sender gets an email saying that it has bounced (even though the script has worked perfectly)
I'm new to this PHP email forwarding with cPanel - so all help would be appreciated!

I'd like to keep this pipe as lean as possible.
 

rpvw

Well-Known Member
Jul 18, 2013
1,101
462
113
UK
cPanel Access Level
Root Administrator

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,909
2,227
463
Hello,

You'd want to use a resource such as the link in the previous post or a website such as StackOverflow for help with the PHP coding itself to ensure the message format is as you intend. As far as the bounce message, what do you see in /var/log/exim_mainlog when that happens?

Thank you.