I have a pipe script in my site which is used to save the incoming mail to a particular address by mail forwarding. The problem is-- when the headers are splitted the message body looks like this :- mail from Gmail =========== ------=_Part_32303_1392883.1213689567031 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Testing Email. ------=_Part_32303_1392883.1213689567031 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Testing Email.<br> ------=_Part_32303_1392883.1213689567031-- if the mail is from yahoo the format is different. Can anyone please give me a solution to extract only the message from this. ie i want to remove the parts like--(------=_Part_32303_1392883.1213689567031 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline) Please help..... Thanks in advance
Thanks Eric,Glad to see someone noticed my post. Let me describe the problem. =========================== In my site say 'mysite.com' there is an email id say 'support@mysite.com'. Each mail to this id will be forwarded to a php script(email piping) which splits the email headers like 'From','Subject','Messagebody' etc apart and saves to my DB. The problem is after splitting, the message body looks like this: ------=_Part_32303_1392883.1213689567031 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Testing Email. ------=_Part_32303_1392883.1213689567031 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Testing Email.<br> ------=_Part_32303_1392883.1213689567031-- ======================= Here the actual message is 'Testing Email.',and all the other charecters are overheads.I want to remove those parts from the messagebody. Can u help me? Waiting for ur reply..........
Here is the code ============= $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); // empty vars $from = ""; $replyto = ""; $subject = ""; $headers = ""; $message = ""; $split = true; // handle email $lines = explode("\n", $email); for ($i=0; $i<count($lines); $i++) { if ($split) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } if (preg_match("/^Reply-To: (.*)/", $lines[$i], $matches)) { $replyto = $matches[1]; } } else { // not a header, but message $message .= $lines[$i]."\n"; } if (trim($lines[$i])=="") { // empty line, header section has ended $split = false; } } ===================================== Here $message is the message body.