BASE64 to Plain Text

You want to get involved in the Opencaching Network?
RVRoadTrip

Our current code for that section was this:

$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-Type: text/plain; charset=utf-8\r\n";
$email_headers .= "From: Opencaching US <notify@opencaching.us>\r\n";
$email_headers .= "Reply-To: noreply@opencaching.us\r\n";

I am testing the code you suggested in its place.  We shall see...
RVRoadTrip

The new code did not work.  Still garbled...

Content-Type: text/plain; charset=utf-8
From: Opencaching US <octeam@opencaching.us>
Reply-To: octeam@opencaching.us
Mime-Version: 1.0
Content-Transfer-Encoding: BASE64
Message-Id: <20101216225600.87A3FC25E@opencaching.us>
Date: Thu, 16 Dec 2010 22:56:00 +0000 (UTC)

V2UncmUgdGVzdGluZyBhIG5ldyBzZWN0aW9uIG9mIGNvZGUgdHJ5aW5nIHRvIGVsaW1pbmF0ZSB0
aGUgZ2FyYmxlZCBlbWFpbHMgdGhhdCBzb21lIHVzZXJzIGhhdmUgcmVjZWl2ZWQuIFRoZSBlbWFp
bHMgaW4gcXVlc3Rpb24gYXJlIHNpbXBseSBiZWluZyBCQVNFNjQgZW5jb2RlZCBidXQgdGhlIGVt
YWlsIGNsaWVudCBpcyBub3QgZGVjb2RpbmcgaXQuICBJZiB5b3UgZXZlciBkbyByZWNlaXZlIGEg
Z2FyYmxlZCBlbWFpbCwgaXQgY2FuIGJlIGRlY29kZWQgYXQgaHR0cDovL3d3dy5vcGluaW9uYXRl
ZGdlZWsuY29tL2RvdG5ldC90b29scy9iYXNlNjRkZWNvZGUvDQoNClRoYW5rcyBmb3IgeW91ciBw
YXRpZW5jZSENCg0KSmVycnkNCk9DUyBBZG1pbg0KDUlmIHlvdSBkbyBub3Qgd2lzaCB0byByZWNl
aXZlIG5ld3MgYnVsbGV0aW5zIGZyb20gT0MgVVMsIHlvdSBtYXkgY2hhbmdlIHlvdXIgYWNjb3Vu
dCBzZXR0aW5ncyBhdCBodHRwOi8vd3d3Lm9wZW5jYWNoaW5nLnVzL215cHJvZmlsZS5waHA/YWN0
aW9uPWNoYW5nZS4=
Zuletzt geändert von RVRoadTrip am 17.12.2010, 01:22, insgesamt 1-mal geändert.
OlofL

Not good at all since I think the mail headers and the mail is a valid e-mail.

Not sending base64 would then be the only option. There are several changes neede for this. In theory it is these (though I cannot test them myself until Sunday):

The line that describes what the encoding of the contents of the mail message are after being decoded is:

Content-Type: text/plain; charset=utf-8

If you want to send plain ascii instead of utf-8 to the users (preventing åäö and other special characters) you need to convert it. I'm not sure that this method handles non convertable letters or if it gives an error, but probably you can change encoding of the message by:
$body = mb_convert_encoding($body,'ASCII'),
to ascii.
The use this header instead:

Content-type: text/plain; charset=us-ascii

After these changes of message encoding you can replace mb_send_mail() with only mail(). Or perhaps change the mb_language("en") as in my first post, I'm not sure if that works.

I'm starting to suspect that there is more than one issue here. One with the headers, and one is with e-mail clients that cannot handle non-ascii characters. In countries where non-ascii characters are common the second problem is uncommon since the users of such mail clients are rare.
sp2ong

Maybe help this doc RFC http://www.ietf.org/rfc/rfc2045.txt
RVRoadTrip

Here is a message I received to day.  Does this info provide any insight to the problem?


------------------------
Hi, I have been receiving garbled email for some kinds of messages but not others. The email announcing a new cache is garbled. PM I received from a CO was not. Additionally the body of the garbled email is doublespaced in part but not in whole. See, for example this example:

...valid header stuff above left off...
---
Received: from 184-106-211-113.static.cloud-ips.com (HELO opencaching.us) ([184.106.211.113])
by os-mail-4.tamu.edu with ESMTP; 02 Jan 2011 21:00:17 -0600
Received: by opencaching.us (Postfix, from userid 33)
id DF387C001; Mon, 3 Jan 2011 03:00:01 +0000 (UTC)
To: furuta@cs.tamu.edu
Subject: [OC US] New Cache: MSC Webcam
X-PHP-Originating-Script: 33:run_notify.php
MIME-Version: 1.0
Message-Id: <20110103030017.EFBDB2FC06B@smtp.cs.tamu.edu>
Date: Sun, 2 Jan 2011 21:00:17 -0600 (CST)
From: www-data@opencaching.us

Content-Type: text/plain; charset=utf-8

From: Opencaching US <notify@opencaching.us>

Reply-To: noreply@opencaching.us

Mime-Version: 1.0
Content-Transfer-Encoding: BASE64
Message-Id: <20110103030001.DF387C001@opencaching.us>
Date: Mon, 3 Jan 2011 03:00:01 +0000 (UTC)

xxxxx

dGhpbiB5b3VyDQpub3RpZmljYXRpb24gcmFkaXVzOg0KDQoNCjAxLjAxLjIwMTEsICBOYXRpdlR4

-----
etc...

It's been a zillion years since I did any work with injecting email into servers, but this looks to me like extra newlines are being inserted into the message causing the header to be terminated early. Also the Message-ID was generated on our local system indicating that the Message-ID in the header wasn't recognized as header material. Also odd are the two From lines. Could this be something as simple as lines being terminated with something like LFCR rather than CRLF? Or some lines terminated with \n and others with \r?

Also of interest is that the PM email worked properly, which implies there is code in the system that is doing the email generation correctly, thereby providing a good example to copy!

Anyway just some rambling thoughts.

--Rick
oliver

[quote="RVRoadTrip"]Could this be something as simple as lines being terminated with something like LFCR rather than CRLF? Or some lines terminated with \n and others with \r?[/quote]

this was my first thought, too. But i dont understand why the base64 part of the message has that wrong line endings.
OlofL

Yes it seems strange with duplicate From and duplicate MIME-Version.

You wrote that your code was:

$email_headers = "MIME-Version: 1.0\r\n";
$email_headers .= "Content-Type: text/plain; charset=utf-8\r\n"; 
$email_headers .= "From: Opencaching US <notify@opencaching.us>\r\n";
$email_headers .= "Reply-To: noreply@opencaching.us\r\n";

Try removing the \r, I think that it should be sufficient with only \n in the header.
Antworten