lmsook
June 25, 2010, 3:32pm
1
Hello,
We decided to change our whole site to utf-8, and we are using Pear mail instead of php mail().
I found we could use mb_mail_send() instead of php mail() if we used php mail() for utf-8 support, but how about Pear mail() ?
Is there a way to send utf-8 in header, subject and body using Pear mail() ?
Thanks,
Working Example
require_once("Mail.php");
require_once("Mail/mime.php");
$headerss=array();
$headerss['From']="info@xxxxxxx.com";
$headerss['To']="info@xxxxxxx.com";
$headerss['Subject']="My Subject";
$headerss['X-Mailer']="X-Mailer: xxxxxx Mailer";
$headerss['X-Priority']=2;
$headerss['Errors-To']="webmaster@xxxxxxx.com";
$headerss['Return-Path']="info@xxxxxxx.com";
$messageTEXT="Body in TXT";
$messageHTML="<b>Body in HTML</b>"
$message = new Mail_mime();
$message->setTXTBody($messageTEXT);
$message->setHTMLBody($messageHTML);
# CHECK THIS OUT FOR UTF-8 *****************************
$mimeparams=array();
$mimeparams['text_encoding']="7bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$body = $message->get($mimeparams);
$headers = $message->headers($headerss);
$smtp = Mail::factory('smtp', array ('host' => "127.0.0.1", 'port'=>25, 'auth' => true, 'username' => "info@xxxxxxx.com", 'password' => "dfsgfgdfgdfgf"));
Check this part
$mimeparams=array();
$mimeparams['text_encoding']="7bit";
$mimeparams['text_charset']="UTF-8";
$mimeparams['html_charset']="UTF-8";
$body = $message->get($mimeparams);
lmsook
June 28, 2010, 8:57pm
3
I got the answer.
One more line
$mimeparams['head_charset']="UTF-8";
makes it work!
lmsook
June 28, 2010, 5:30pm
4
Thanks for the solution, it works for the message body, but how about header?
If I want to use utf-8 in fromName, toName, and subject part, what should I do?
I tried
$hdrs['text_encoding']="7bit";
$hdrs['text_charset']="UTF-8";
$hdrs['html_charset']="UTF-8";
and
$hdrs['Content-Type'] = 'text/html; charset="UTF-8"';
but both do not work. Thanks for your help!