2
0

Zend_Mail-CharacterSets.xml 2.0 KB

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