too long

Here's my PHP script that I use for the intercept:

#!/usr/local/bin/php -q
<?php
//Listen to incoming e-mails
$sock = fopen("php://stdin", 'r');
$email = '';

//Read e-mail into buffer
while (!feof($sock))
{
    $email .= fread($sock, 1024);
}

//Close socket
fclose($sock);

emailPoster('email@address.com', "message");

function emailPoster( $to, $email )
{
    $subject = "Email Intercepted";
    $body = $message;
    $headers    = "To: {$to}
";
    $headers    .= "From: noreply@example.com
";
    $headers    .= "Subject: {$subject}
";
    $headers    .= "Reply-To: noreply@example.com
";
    $headers    .= "Return-Path: noreply@example.com
";
    $headers    .= "MIME-Version: 1.0
";
    $headers    .= "Date: " . date("r") . "
";
    $headers    .= "Content-Type: text/html; charset=ISO-8859-1
";
    $sender     = '-fnoreply@example.com';
    if (mail($to, $subject, $body, $headers, $sender) ){
        echo("<p>Message successfully sent!</p>");
    } else {
        echo("<p>Message delivery failed...</p>");
    }
}
?>

and the pipe command I use in cPanel:

usr/local/bin/php -q /public_html/[mywebsite]/email/intercept.php

When I send an email to the appropriate address, it does process the intercept.php script, but it also returns a bounceback error.

Any ideas?

if you pipe emails to a php script, you can not use "ECHO" or other output command in your script. every output command make error. Also delete "?>" from end of file. every character after this tag make an output header and cause error.

Instead of the echo statement I write it into a file. Make sure the write permissions in the directory are correctly set.

You can always put:

return NULL;

At the end of your PHP file to stop any return messages which will stop the script from bouncing.