I'm having trouble with piping emails to a PHP script. It seems as if the entire email isn't coming through. This is the sort of response I get:
From brian@myemailaddress.com Sun Apr 14 13:12:53 2013
Received: from mailserver.google.com ([GOOGLE.IP.ADDRESS]:41509)
by myhost.server.com with esmtps (TLSv1:RC4-SHA:128)
(Exim 4.80)
(envelope-from <brian@myemailaddress.com>)
id THE-EMAIL-ID
for brian@mysub.domain.com; Sun, 14 Apr 2013 13:12:53 -0400
Received: by mailserver.google.com with SMTP id somesmtp.id
for <brian@mysub.domain.com>; Sun, 14 Apr 2013 10:12:51 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=google.com; s=20120113;
h=x-received:mime-version:x-originating-ip:from:date:message-id
:subject:to:content-type:x-gm-message-state;
bh=rPONCz8eaLlxJpumTQNPIEKBlWcbg53KdugbKjulvj4=;
b=Kr7ZpXKTpXDCoQHmI93Ep+CSv8BY4xT2Pgh3eJeRsz5Y0iAjomGdBQDwKMQ/myk4hz
dkReoFPGAqE3KsRo601JXzgDrvmu9oRDC3UpbwHvMUvbI+U1qjC2rUsp1fmaeohpc99T
tPVMhO9WBBqthUP4TCv/T50/popu771Mydj0YXWbEuRtViyllzTa1M1kO3DhqLC+/bA2
ED2J3wBXp47xRVjkoUNUOzyi5pUIsryDRUh9gxdSQtAGjqAdTpTwQXSX0MAdSK+PYc8Y
oB/5Sm09um8/id4d4YHUBZMbIZv0+L0GR0ZbIfa42l7+WzvKMjijNw7QsA/KDXMaYL5W
CwBQ==
X-Received: by IP.ADDR.ESS with SMTP id some.long.id; Sun,
14 Apr 2013 10:12:51 -0700 (PDT)
MIME-Version: 1.0
Received: by IP.ADDR.ESS with HTTP; Sun, 14 Apr 2013 10:12:31 -0700 (PDT)
X-Originating-IP: [MY.IP.ADDRESS]
From: Brian D. <brian@myemailaddress.com>
Date: Sun, 14 Apr 2013 12:12:31 -0500
Message-ID: <CAOb+JoxnfiaHFSG6RyQPtnmeS526JPMO4krsS96wc3FGMKWOiA@mail.gmail.com>
Subject: New Task.
To: brian@wmysub.domain.com
Content-Type: multipart/alternative; boundary=001a11c30f960b290d04ea583f19
X-Gm-Message-State: AKoCoQnquQFvVi0CYGF4sdhK0Cn2swVezCK1Yg5uXKhxBmnppYCfVX/2+EK37dX1iyV4pxBOM1cJ
The way this is being piped is using cPanel's Default Address feature to work as a catch-all for a specific domain. This is the command:
|/usr/local/bin/php /home/account/path/to/my/script.php
I actually had to manually modify this script in the /etc/valiases file for the domain because it required I use hashbang/shebang at the top of my script and that was causing errors, but this (for the most part) works, but the entire message isn't showing up. Here is the code I'm using to read the message:
$email = '';
$stream = fopen('php://stdin', 'r');
$i = 0;
while($line = stream_get_line($stream, 65535, PHP_EOL)) {
$email .= $line;
$i++;
}
fclose($stream);
Any ideas why I'm not getting the body of the email?