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 (myself@example.com 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.
#!/usr/bin/php -q
<?php
$fd = fopen( "php://stdin", "r" );
$message = "";
while ( !feof( $fd ) )
{
$message .= fread( $fd, 1024 );
}
fclose( $fd );
mail('myself@example.com','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:
- The $message appears in plain text with all of the MIME stuff - so the email just looks like jibberish to the average user.
- 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.
EDIT 1: I've found this question, and it's similar to what I'm looking for (?) It's a bit over my head though: Given an email as raw text, how can I send it using PHP?