fix php 5.6 in docker dev env (#1740)
[openemr.git] / vendor / zendframework / zend-mail / doc / book / message / character-sets.md
blobbe73417c027382b347501a31914a722064594e84
1 # Character Sets
3 `Zend\Mail\Message` assumes a default ASCII character set, and headers and
4 content are quoted accordingly. If you wish to specify alternate characters
5 sets, you will need to:
7 - Notify the `Message` instance of the desired character-set encoding, to ensure
8   headers are encoded correctly.
9 - Set an appropriate `Content-Type` header.
10 - In multipart messages, set the character set per-part.
12 > ### Only in text format
13
14 > Character sets are only applicable for message parts in text format.
16 ## Example
18 The following example is how to use `Zend\Mail\Message` to send a message in
19 Japanese.
21 ```php
22 use Zend\Mail\Message;
23 use Zend\Mime\Message as MimeMessage;
24 use Zend\Mime\Mime;
25 use Zend\Mime\Part as MimePart;
27 // Typically, PHP will use UTF-8 internally; the following converts
28 // the text to a Japanese encoding.
29 function convertToJapaneseEncoding($string) {
30     return mb_convert_encoding($string, 'ISO-2022-JP', 'UTF-8');
33 $mail = new Message();
35 // Set message encoding; this only affects headers.
36 $mail->setEncoding('ISO-2022-JP');
38 // Set the message content type:
39 $mail->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=ISO-2022-JP');
41 // Add some headers. Textual content needs to be encoded first.
42 $mail->setFrom('somebody@example.com', convertToJapaneseEncoding('Some Sender'));
43 $mail->addTo('somebody_else@example.com', convertToJapaneseEncoding('Some Recipient'));
44 $mail->setSubject(convertToJapaneseEncoding('TestSubject'));
46 // Create a MIME part specifying 7bit encoding:
47 $part = new MimePart(convertToJapaneseEncoding($content));
48 $part->encoding = Mime::ENCODING_7BIT;
50 // Create a MIME message, add the part, and attach it to the mail message:
51 $body = new MimeMessage();
52 $body->addPart($part);
53 $mail->setBody($body);
54 ```