Send Unicode attachment with mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
marcomarino
Forum Newbie
Posts: 3
Joined: Fri May 30, 2008 8:14 pm

Send Unicode attachment with mail

Post 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?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Send Unicode attachment with mail

Post 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.
marcomarino
Forum Newbie
Posts: 3
Joined: Fri May 30, 2008 8:14 pm

Re: Send Unicode attachment with mail

Post 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
marcomarino
Forum Newbie
Posts: 3
Joined: Fri May 30, 2008 8:14 pm

Re: Send Unicode attachment with mail

Post by marcomarino »

Chris,
I tried with Japanese text and it didn't work. How can I make it work with unicode text?
Post Reply