Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit a4c4ae6

Browse files
committed
Merge branch 'feature/documentation'
Close #88
2 parents 3ca1205 + 52be2e8 commit a4c4ae6

21 files changed

+1909
-841
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
.*.sw*
77
.*.un~
88
nbproject
9+
doc/html/
910
tmp/
11+
vendor/
12+
zf-mkdoc-theme/
1013

1114
clover.xml
1215
composer.lock
1316
coveralls-upload.json
1417
phpunit.xml
15-
vendor

.travis.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ language: php
44

55
branches:
66
except:
7-
- /^release-.*$/
7+
- /^release-\d+\.\d+\.\d+.*$/
88
- /^ghgfk-.*$/
99

1010
cache:
1111
directories:
1212
- $HOME/.composer/cache
13+
- vendor
14+
- $HOME/.local
15+
- zf-mkdoc-theme
1316

1417
env:
1518
global:
1619
- SERVICE_MANAGER_VERSION="^3.0.3"
20+
- SITE_URL: https://zendframework.github.io/zend-mail
21+
- GH_USER_NAME: "Matthew Weier O'Phinney"
22+
- GH_USER_EMAIL: [email protected]
23+
- GH_REF: github.com/zendframework/zend-mail.git
24+
- secure: "D/LfNRozbXUjssR19Yi+6luLML1XyVhTLaky2FPlFAuWb80viVzTxhlvX1QgWPSxxTH8zLRlPm/71E8wYHTN94UGLwJorOthA/btaWKPtdgJtlHXErSgofVVOUqAObvGFOW9sSSuRZ5gFN0c47uuWJmYbiI3HUQkFMjpGpFatXO1SajzK+dCpN4cuhgHW3T41PNbiG8RRCYeFwGBJdpIXEm3HYN6bAWRbFnnu4uCVnQYZnDn/Rprr8+WIU5JFOJQ7ttCQuq1RMP3EC1fVIr0N5gFL91KYX9EyCYmLpZNMS6kF9cPTRQbMEOcKMXqqfGA031MlhvveeOiVWiap/ScMwpId0ugTq9O+sUvBHZuk4FSRtiURcPTLKAmQfUie8Zb+/dxKI18oOWVLsUU919wAEU/hGeTOvATl0WcjqZ2LmxOLVm6UE8+5kM1FhM04XjQaFSJVWK+Asto9KRrOSd310SMpluATutO2ZSN0r7+a7S65M38RRh63NOtdrtbbYIx7+MdAmfPwH5+wr3gekD0pDgnfQd1zLQNWMF/2idTjoxO6xAxTLvthThf5ANXadz1A2Dwqn1EdGsTJ2QItGO7TFwDE+Wfi1O6vtm2FgEy98vwC0t4D1op+0QSRMPr6lFkzINOv4aVO/SB1NF3zwiB95ZsvqReU/Zj2+aDzltf5tY="
1725

1826
matrix:
1927
fast_finish: true
@@ -27,6 +35,8 @@ matrix:
2735
- php: 5.6
2836
env:
2937
- EXECUTE_TEST_COVERALLS=true
38+
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
39+
- PATH="$HOME/.local/bin:$PATH"
3040
- php: 5.6
3141
env:
3242
- SERVICE_MANAGER_VERSION="^2.7.5"
@@ -58,6 +68,10 @@ script:
5868
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
5969
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
6070
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; fi
71+
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi
72+
73+
after_success:
74+
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi
6175

6276
after_script:
6377
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file, in reverse
88

99
- [#38](https://github.com/zendframework/zend-mail/pull/38) adds support in the
1010
IMAP protocol adapter for fetching items by UID.
11+
- [#88](https://github.com/zendframework/zend-mail/pull/88) adds and publishes
12+
documentation to https://zendframework.github.io/zend-mail/
1113

1214
### Deprecated
1315

doc/book/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div class="container">
2+
<div class="jumbotron">
3+
<h1>zend-mail</h1>
4+
5+
<p>Parse, create, store, and send email messages, using a variety of storage and transport protocols.</p>
6+
7+
<pre><code class="language-bash">$ composer require zendframework/zend-mail</code></pre>
8+
</div>
9+
</div>
10+

doc/book/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../README.md

doc/book/intro.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Introduction
2+
3+
zend-mail provides generalized functionality to compose and send both text and
4+
MIME-compliant multipart email messages. Mail can be sent with zend-mail via any
5+
of the Sendmail, SMTP, or file-based transports it defines. You can also
6+
implement your own transport by implementing the
7+
`Zend\Mail\Transport\TransportInterface`.
8+
9+
## Basic email
10+
11+
A basic email consists of one or more recipients, a subject, a body and a
12+
sender. To send such a mail using `Zend\Mail\Transport\Sendmail`, do the
13+
following:
14+
15+
```php
16+
use Zend\Mail;
17+
18+
$mail = new Mail\Message();
19+
$mail->setBody('This is the text of the email.');
20+
$mail->setFrom('[email protected]', "Sender's name");
21+
$mail->addTo('[email protected]', 'Name of recipient');
22+
$mail->setSubject('TestSubject');
23+
24+
$transport = new Mail\Transport\Sendmail();
25+
$transport->send($mail);
26+
```
27+
28+
> ### Minimum definitions
29+
>
30+
> In order to send an email using zend-mail you have to specify at least one
31+
> recipient as well as a message body. Please note that each transport may
32+
> require additional parameters to be set.
33+
34+
For most mail attributes there are "get" methods to read the information stored
35+
in the message object. for further details, please refer to the API
36+
documentation.
37+
38+
## Configuring the default sendmail transport
39+
40+
The default transport is `Zend\Mail\Transport\Sendmail`. It is a wrapper to the
41+
PHP [mail()](http://php.net/mail) function. If you wish to pass additional
42+
parameters to the [mail()](http://php.net/mail) function, create a new transport
43+
instance and pass your parameters to the constructor.
44+
45+
### Passing additional mail() parameters
46+
47+
This example shows how to change the Return-Path of the
48+
[mail()](http://php.net/mail) function.
49+
50+
```php
51+
use Zend\Mail;
52+
53+
$mail = new Mail\Message();
54+
$mail->setBody('This is the text of the email.');
55+
$mail->setFrom('[email protected]', 'Dolf');
56+
$mail->addTo('[email protected]', 'Matthew');
57+
$mail->setSubject('TestSubject');
58+
59+
$transport = new Mail\Transport\Sendmail('[email protected]');
60+
$transport->send($mail);
61+
```
62+
63+
> ### Chose your transport wisely
64+
>
65+
> Although the sendmail transport is the transport that requires least
66+
> configuration, it may not be suitable for your production environment. This is
67+
> because emails sent using the sendmail transport will be more often delivered
68+
> to SPAM-boxes. This can partly be remedied by using the
69+
> [SMTP Transport](transport/intro.md#smtp-transport-usage) combined with an SMTP
70+
> server that has an overall good reputation. Additionally, techniques such as
71+
> SPF and DKIM may be employed to ensure even more email messages are delivered
72+
> successfully.
73+
74+
> ### Warning: Sendmail Transport and Windows
75+
>
76+
> As the PHP manual states, the `mail()` function has different behaviour on
77+
> Windows than it does on \*nix based systems. Using the sendmail transport on
78+
> Windows will not work in combination with `addBcc()`. The `mail()` function
79+
> will send to the BCC recipient such that all the other recipients can see that
80+
> address as the recipient!
81+
>
82+
> Therefore if you want to use BCC on a windows server, use the SMTP transport
83+
> for sending!

doc/book/message/attachments.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Adding Attachments
2+
3+
zend-mail does not directly provide the ability to create and use mail
4+
attachments. However, it allows using `Zend\Mime\Message` instances, from the
5+
[zend-mime](https://github.com/zendframework/zend-mime) component, for message
6+
bodies, allowing you to create multipart emails.
7+
8+
## Basic multipart content
9+
10+
The following example creates an email with two parts, HTML content and an
11+
image.
12+
13+
```php
14+
use Zend\Mail\Message;
15+
use Zend\Mime\Message as MimeMessage;
16+
use Zend\Mime\Mime;
17+
use Zend\Mime\Part as MimePart;
18+
19+
$html = new MimePart($htmlMarkup);
20+
$html->type = Mime::TYPE_HTML;
21+
$html->charset = 'utf-8';
22+
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
23+
24+
$image = new MimePart(fopen($pathToImage, 'r'));
25+
$image->type = 'image/jpeg';
26+
$image->filename = 'image-file-name.jpg';
27+
$image->disposition = Mime::DISPOSITION_ATTACHMENT;
28+
$image->encoding = Mime::ENCODING_BASE64;
29+
30+
$body = new MimeMessage();
31+
$body->setParts([$html, $image]);
32+
33+
$message = new Message();
34+
$message->setBody($body);
35+
$message->getHeaders()->addHeaderLine('Content-Type', 'multipart/related');
36+
```
37+
38+
Note that the above code requires us to manually specify the message content
39+
type; zend-mime does not automatically select the multipart type for us, nor
40+
does zend-mail populate it by default.
41+
42+
## multipart/alternative content
43+
44+
One of the most common email types sent by web applications is
45+
`multipart/alternative` messages with both text and HTML parts.
46+
47+
```php
48+
use Zend\Mail\Message;
49+
use Zend\Mime\Message as MimeMessage;
50+
use Zend\Mime\Mime;
51+
use Zend\Mime\Part as MimePart;
52+
53+
$text = new MimePart($textContent);
54+
$text->type = Mime::TYPE_TEXT;
55+
$text->charset = 'utf-8';
56+
$text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
57+
58+
$html = new MimePart($htmlMarkup);
59+
$html->type = Mime::TYPE_HTML;
60+
$html->charset = 'utf-8';
61+
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
62+
63+
$body = new MimeMessage();
64+
$body->setParts([$text, $html]);
65+
66+
$message = new Message();
67+
$message->setBody($body);
68+
$message->getHeaders()->addHeaderLine('Content-Type', 'multipart/alternative');
69+
```
70+
71+
The only differences from the first example are:
72+
73+
- We have text and HTML parts instead of an HTML and image part.
74+
- The `Content-Type` header is now `multipart/alternative`.
75+
76+
## multipart/alternative emails with attachments
77+
78+
Another common task is creating `multipart/alternative` emails where the HTML
79+
content refers to assets attachments (images, CSS, etc.).
80+
81+
To accomplish this, we need to:
82+
83+
- Create a `Zend\Mime\Part` instance containing our `multipart/alternative`
84+
message.
85+
- Add that part to a `Zend\Mime\Message`.
86+
- Add additional `Zend\Mime\Part` instances to the MIME message.
87+
- Attach the MIME message as the `Zend\Mail\Message` content body.
88+
- Mark the message as `multipart/related` content.
89+
90+
The following example creates a MIME message with three parts: text and HTML
91+
alternative versions of an email, and an image attachment.
92+
93+
```php
94+
use Zend\Mail\Message;
95+
use Zend\Mime\Message as MimeMessage;
96+
use Zend\Mime\Mime;
97+
use Zend\Mime\Part as MimePart;
98+
99+
$body = new MimeMessage();
100+
101+
$text = new MimePart($textContent);
102+
$text->type = Mime::TYPE_TEXT;
103+
$text->charset = 'utf-8';
104+
$text->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
105+
106+
$html = new MimePart($htmlMarkup);
107+
$html->type = Mime::TYPE_HTML;
108+
$html->charset = 'utf-8';
109+
$html->encoding = Mime::ENCODING_QUOTEDPRINTABLE;
110+
111+
$content = new MimeMessage();
112+
$content->setParts([$text, $html]);
113+
114+
$contentPart = new MimePart($content->generateMessage());
115+
$contentPart->type = sprintf(
116+
"multipart/alternative\n boundary=\"%s\",
117+
$content->getMime()->boundary()
118+
);
119+
120+
$image = new MimePart(fopen($pathToImage, 'r'));
121+
$image->type = 'image/jpeg';
122+
$image->filename = 'image-file-name.jpg';
123+
$image->disposition = Mime::DISPOSITION_ATTACHMENT;
124+
$image->encoding = Mime::ENCODING_BASE64;
125+
126+
$body = new MimeMessage();
127+
$body->setParts([$contentPart, $image]);
128+
129+
$message = new Message();
130+
$message->setBody($body);
131+
$message->geHeaders()->addHeaderLine('Content-Type', 'multipart/related');
132+
```
133+
134+
## Setting custom MIME boundaries
135+
136+
In a multipart message, a MIME boundary for separating the different parts of
137+
the message is normally generated at random. In some cases, however, you might
138+
want to specify the MIME boundary that is used. This can be done by injecting a
139+
new `Zend\Mime\Mime` instance into the MIME message.
140+
141+
```php
142+
use Zend\Mime\Mime;
143+
144+
$mimeMessage->setMime(new Mime($customBoundary));
145+
```

doc/book/message/character-sets.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Character Sets
2+
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:
6+
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.
11+
12+
> ### Only in text format
13+
>
14+
> Character sets are only applicable for message parts in text format.
15+
16+
## Example
17+
18+
The following example is how to use `Zend\Mail\Message` to send a message in
19+
Japanese.
20+
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;
26+
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');
31+
}
32+
33+
$mail = new Message();
34+
35+
// Set message encoding; this only affects headers.
36+
$mail->setEncoding('ISO-2022-JP');
37+
38+
// Set the message content type:
39+
$mail->getHeaders()->addHeaderLine('Content-Type', 'text/plain; charset=ISO-2022-JP');
40+
41+
// Add some headers. Textual content needs to be encoded first.
42+
$mail->setFrom('[email protected]', convertToJapaneseEncoding('Some Sender'));
43+
$mail->addTo('[email protected]', convertToJapaneseEncoding('Some Recipient'));
44+
$mail->setSubject(convertToJapaneseEncoding('TestSubject'));
45+
46+
// Create a MIME part specifying 7bit encoding:
47+
$part = new MimePart(convertToJapaneseEncoding($content));
48+
$part->encoding = Mime::ENCODING_7BIT;
49+
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+
```

0 commit comments

Comments
 (0)