How to send UTF-8 email?

deepWebMie picture deepWebMie · Sep 1, 2011 · Viewed 201.6k times · Source

When I send out the email, the email does not show characters other than english. It does show like below:

余生ä»ä»

May know actually what cause this? Even I tried to added Content-type and charset in the script, it still show the same.

I used Mail::Factory("mail");

Answer

s.webbandit picture s.webbandit · Sep 1, 2011

You can add header "Content-Type: text/html; charset=UTF-8" to your message body.

$headers = "Content-Type: text/html; charset=UTF-8";

If you use native mail() function $headers array will be the 4th parameter mail($to, $subject, $message, $headers)

If you user PEAR Mail::factory() code will be:

$smtp = Mail::factory('smtp', $params);

$mail = $smtp->send($to, $headers, $body);