Computing.Net > Forums > Web Development > E-mail Piping Format (PHP)

E-mail Piping Format (PHP)

Reply to Message Icon

Original Message
Name: -Bryan-
Date: November 1, 2004 at 22:29:18 Pacific
Subject: E-mail Piping Format (PHP)
OS: XP Pro
CPU/Ram: Pentium 4
Comment:

Okay, this one has been bothering me all day.

I am piping e-mails to a php script. The script basically resends the received e-mail to me (will be sent to others shortly, alla a mailing list). The problem is that when the script receives a mail in HTML format, it really looks crazy when I get it, i.e. tons of code, what appears to be headers of some sort, etc.

I know there is a way of fixing this, but it's completely slipping my mind right now. Any help would be greatly appreciated. Thanks!

Bryan



Report Offensive Message For Removal


Response Number 1
Name: FBI Agent
Date: November 2, 2004 at 08:17:56 Pacific
Reply: (edit)

maybe you should give us some information about the problem. something like a code snippet of the "tons of code" that go with the email or how your php script works (or exactly what it is). that information would help.

FBI Agent

AIM: EliteAssassin187


Report Offensive Follow Up For Removal

Response Number 2
Name: -Bryan-
Date: November 2, 2004 at 11:06:24 Pacific
Reply: (edit)

Okay, in regards to the problem...there is a bunch of extra info present when I use HTML format e-mails. I'll include a sample at the end.

The script works using a standard method mail to PHP script pipe. Using STDIN, the script "receives" the e-mail, and splits it into from, subject, header, and message.

Here's the portion of the code that does the work:

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);

// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
// 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];
}
} else {
// e-mail body
$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}

and here are what the results look like when receiving an HTML e-mail:

This is a multi-part message in MIME format.

------=_NextPart_000_0057_01C4C024.D1C4AE60
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

testing
------=_NextPart_000_0057_01C4C024.D1C4AE60
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2523" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>testing</DIV></BODY></HTML>

------=_NextPart_000_0057_01C4C024.D1C4AE60--


Report Offensive Follow Up For Removal

Response Number 3
Name: -Bryan-
Date: November 2, 2004 at 11:12:17 Pacific
Reply: (edit)

Should also add that the script works great with plain text e-mails. No problems at all.


Report Offensive Follow Up For Removal

Response Number 4
Name: FBI Agent
Date: November 4, 2004 at 07:59:08 Pacific
Reply: (edit)

i think there's a PHP function that destroys all html code from text. i dont remember what it is but im almost 100% sure that it had that function. i dont have the internet right now at my house im at my school now, so you could look for the function at http://www.php.net

or just go on google or something. but yeah, there should be a way to fix it using the prescribed method

FBI Agent

AIM: EliteAssassin187


Report Offensive Follow Up For Removal

Response Number 5
Name: -Bryan-
Date: November 4, 2004 at 12:53:07 Pacific
Reply: (edit)

Hey FBI, thanks for the info.

Yeah, I tried that. I found a PHP class to do that, but it still leaves the MIME headers at the top.

A means of forcing the script to only accept text-based e-mails would work too. LOL!

Bryan


Report Offensive Follow Up For Removal


Response Number 6
Name: FBI Agent
Date: November 5, 2004 at 08:13:49 Pacific
Reply: (edit)

well good that i could help you. your welcome

FBI Agent

AIM: EliteAssassin187


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: E-mail Piping Format (PHP)

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 6 Days.
Discuss in The Lounge