Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UTF-8 sender name in Zend_Mail?

I am using Zend_Mail and want to customize the sender name.

I want the sender name to be FooBar爱你Ryan (where 'Ryan' gets replaced with the recipient name and 爱你 gets replaced with the translation for 'loves' in the language of the recipient, just like CD Baby does).

I've tried base64_encode and mb_encode_mimeheader() and other things like:

mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
iconv_set_encoding("input_encoding", 'UTF-8');
iconv_set_encoding("output_encoding", 'UTF-8');
iconv_set_encoding("internal_encoding", 'UTF-8'); 
header('Content-Type:text/html; charset=' . 'UTF-8');

It generates this as the sender: '=?UTF-8?B?RXh0cmFidXjniLHkvaByY3dhbHNoQGV4dHJhYnV4LmNvbQ==?= <[email protected]>'

And then that appears in my Gmail as (unknown sender).

Any ideas?

like image 422
Ryan Avatar asked Oct 22 '22 21:10

Ryan


2 Answers

For me the only solution worked was the following: As you'd set utf8 subject in a usual php sendmail case, you can make a utf8 noted base64 string like this:

$mail->addFrom($fromEmail, '=?utf-8?B?'.base64_encode($fromName).'?=');

With this solution every thing worked like a charm.

like image 152
LWjuniOr Avatar answered Nov 15 '22 04:11

LWjuniOr


I wish I had tried this earlier: when I hard code the Chinese string as the sender name (using utf8 characters), it works fine. (I tested in Gmail only.)

So the path I'd been going down was mistaken.

I need to figure out why a dynamically-generated sender name consisting of utf8 characters doesn't work when a hard-coded Chinese string does. But that seems to be a different question.

like image 41
Ryan Avatar answered Nov 15 '22 05:11

Ryan