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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

E-mail Piping Format (PHP)

Reply to Message Icon

Name: -Bryan-
Date: November 1, 2004 at 22:29:18 Pacific
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




Sponsored Link
Ads by Google

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

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


0

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

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--


0

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

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


0

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

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


0

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

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


0

Related Posts

See More



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

well good that i could help you. your welcome

FBI Agent

AIM: EliteAssassin187


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: E-mail Piping Format (PHP)

PHP e-mail form: Option element www.computing.net/answers/webdevel/php-email-form-option-element/3147.html

(PHP) Form sending e-mail www.computing.net/answers/webdevel/php-form-sending-email/3670.html

Hide e-mail address www.computing.net/answers/webdevel/hide-email-address/1457.html