Zend_Mail-CharacterSets.xml 2.0 KB

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