1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.mail.character-sets">
4 <title>Character Sets</title>
7 <classname>Zend_Mail</classname> does not check for the correct character set of the mail
8 parts. When instantiating <classname>Zend_Mail</classname>, a charset for the e-mail itself
9 may be given. It defaults to <code>iso-8859-1</code>. The application has to make sure that
10 all parts added to that mail object have their content encoded in the correct character set.
11 When creating a new mail part, a different charset can be given for each part.
15 <title>Only in text format</title>
18 Character sets are only applicable for message parts in text format.
22 <example id="zend.mail.character-sets.cjk">
23 <title>Usage in CJK languages</title>
26 The following example is how to use <classname>Zend_Mail</classname> in Japanese. This
27 is one of <acronym>CJK</acronym> (aka <acronym>CJKV</acronym> ) languages. If you use
28 Chinese, you may use <acronym>HZ-GB-2312</acronym> instead of
29 <acronym>ISO-2022-JP</acronym>.
32 <programlisting language="php"><![CDATA[
33 //We suppose that character encoding of strings is UTF-8 on PHP script.
34 function myConvert($string) {
35 return mb_convert_encoding($string, 'ISO-2022-JP', 'UTF-8');
38 $mail = new Zend_Mail('ISO-2022-JP');
39 // In this case, you can use ENCODING_7BIT
40 // because the ISO-2022-JP does not use MSB.
42 myConvert('This is the text of the mail.'),
44 Zend_Mime::ENCODING_7BIT
46 $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
47 $mail->setFrom('somebody@example.com', myConvert('Some Sender'));
48 $mail->addTo('somebody_else@example.com', myConvert('Some Recipient'));
49 $mail->setSubject(myConvert('TestSubject'));