Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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-printabletesting
------=_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--

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

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

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |