Zend_Mail-CharacterSets.xml 2.0 KB

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