Page 1 of 1

Send Unicode attachment with mail

Posted: Fri May 30, 2008 8:18 pm
by marcomarino
Hi,
from MacOS X, I send data (one char only just to test) to my php script (to the variable $name) .
I verify on Mac the unichar I send is 'é' (e lowercase with acute accent) which printed on Mac with NSLog as %d is 233. Well, on my php I echo the ord($name[0]) and it properly shows 233. Perfect.

Now I have to send an email containing a text file as attachment containing that $name.
So, in my multiple header I do:

$attachment = chunk_split(base64_encode($name));

$message .= "Content-type: application/octet-stream; name=\"MyTextFile.txt\"\n";
$message .= "Content-disposition: attachment\n";
$message .= "Content-transfer-encoding: base64\n\n";/
$message .= $attachment . "\n\n";

Well, I receive an email with the attachment (a text file), but this text file contains an 'È' (uppercase E with grave accent). Wrong. I tried several conversions with mb_convert_encoding unsuccessfully.

What do I miss? Is anyone who knows how to fix this trouble? Which conversion should I do?

Re: Send Unicode attachment with mail

Posted: Sat May 31, 2008 3:03 am
by Chris Corbyn
Content-Type: text/plain; charset=<your charset here>; name="My file.txt"

However, your problem is nothing to do with your attachment. It's that whatever text editor you're opening the file in isn't being told what charset the file is.

Re: Send Unicode attachment with mail

Posted: Sat May 31, 2008 8:28 am
by marcomarino
Chris, THANK YOU!
It has worked at the first shot.
Amazing, I have spent 2 days (and nights) unsuccessfully, and now...
it works!!!! Now I'm going to try it with Japanese strings and so on.

Again, thanks.

Marco

Re: Send Unicode attachment with mail

Posted: Sat May 31, 2008 5:08 pm
by marcomarino
Chris,
I tried with Japanese text and it didn't work. How can I make it work with unicode text?