I am trying to deal with multipart email's & having not much success, wonder if anyone can reccommend a good class or tutorial or advice?
I am using the following :
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
$lines = explode("\n", $email);
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
$headers .= $lines[$i]."\n";
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches))
$subject = $matches[1];
if (preg_match("/^From: (.*)/", $lines[$i], $matches))
$from = $matches[1];
if (preg_match("/^To: (.*)/", $lines[$i], $matches))
$to = $matches[1];
} else
$message .= $lines[$i]."\n";
if (trim($lines[$i])=="")
$splittingheaders = false;
}
Ideally, I would like to filter out quoted text & sort thru multipart messages, saving only the plain text body... (the rest works great).
I have been at this for days without success, any help would be much appreciated!
Also I have setup a forwarder to :
|php -q /home/user/public_html/myscript/pipe.php
Which works great! The email goes into my database, etc no problem... but it also send the sending email address an undeliverabe as well each time.. which is strange : as follows :
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
pipe to |"/usr/local/bin/php -q /home/user/public_html/myscript/pipe.php"
generated by help@mydomain.com
local delivery failed
------ This is a copy of the message, including all the headers. ------
etc........