@@ -32,7 +32,7 @@ return [
32
32
Basic usage
33
33
-----------
34
34
35
- Once the ' mailer' component is configured, you can use the following code to send an email message:
35
+ Once the ` mailer ` component is configured, you can use the following code to send an email message:
36
36
37
37
``` php
38
38
Yii::$app->mailer->compose()
@@ -50,18 +50,18 @@ You may put more complex logic in this process if needed:
50
50
``` php
51
51
$message = Yii::$app->mailer->compose();
52
52
if (Yii::$app->user->isGuest) {
53
- $message->setFrom('
[email protected] ')
53
+ $message->setFrom('
[email protected] ')
;
54
54
} else {
55
- $message->setFrom(Yii::$app->user->identity->email)
55
+ $message->setFrom(Yii::$app->user->identity->email);
56
56
}
57
57
$message->setTo(Yii::$app->params['adminEmail'])
58
58
->setSubject('Message subject')
59
59
->setTextBody('Plain text content')
60
60
->send();
61
61
```
62
62
63
- > Note: each ' mailer' extension comes in 2 major classes: ' Mailer' and ' Message'. ' Mailer' always knows
64
- the class name and specific of the ' Message' . Do not attempt to instantiate ' Message' object directly -
63
+ > Note: each ` mailer ` extension comes in 2 major classes: ` Mailer ` and ` Message ` . ` Mailer ` always knows
64
+ the class name and specific of the ` Message ` . Do not attempt to instantiate ` Message ` object directly —
65
65
always use ` compose() ` method for it.
66
66
67
67
You may also send several messages at once:
@@ -83,7 +83,7 @@ Composing mail content
83
83
----------------------
84
84
85
85
Yii allows composition of the actual mail messages content via special view files.
86
- By default these files should be located at ' @app/mail ' path.
86
+ By default these files should be located at ` @app/mail ` path.
87
87
88
88
Example mail view file content:
89
89
@@ -92,7 +92,6 @@ Example mail view file content:
92
92
use yii\helpers\Html;
93
93
use yii\helpers\Url;
94
94
95
-
96
95
/* @var $this \yii\web\View view component instance */
97
96
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */
98
97
@@ -175,10 +174,10 @@ You can add attachments to message using methods `attach()` and `attachContent()
175
174
``` php
176
175
$message = Yii::$app->mailer->compose();
177
176
178
- // Attach file from local file system:
177
+ // attach file from local file system
179
178
$message->attach('/path/to/source/file.pdf');
180
179
181
- // Create attachment on-the-fly
180
+ // create attachment on-the-fly
182
181
$message->attachContent('Attachment content', ['fileName' => 'attach.txt', 'contentType' => 'text/plain']);
183
182
```
184
183
@@ -187,7 +186,7 @@ Embedding images
187
186
----------------
188
187
189
188
You can embed images into the message content using ` embed() ` method. This method returns the attachment id,
190
- which should be then used at ' img' tag.
189
+ which should be then used at ` img ` tag.
191
190
This method is easy to use when composing message content via view file:
192
191
193
192
``` php
@@ -209,7 +208,7 @@ Testing and debugging
209
208
A developer often has to check, what actual emails are sent by the application, what was their content and so on.
210
209
Such ability is granted by Yii via ` yii\mail\BaseMailer::useFileTransport ` . If enabled, this option enforces
211
210
saving mail message data into the local files instead of regular sending. These files will be saved under
212
- ` yii\mail\BaseMailer::fileTransportPath ` , which is ' @runtime/mail ' by default.
211
+ ` yii\mail\BaseMailer::fileTransportPath ` , which is ` @runtime/mail ` by default.
213
212
214
213
> Note: you can either save the messages to the files or send them to the actual recipients, but can not do both simultaneously.
215
214
@@ -223,8 +222,8 @@ This mechanism may prove itself, while debugging application or running unit tes
223
222
Creating your own mail solution
224
223
-------------------------------
225
224
226
- In order to create your own custom mail solution, you need to create 2 classes: one for the ' Mailer' and
227
- another one for the ' Message' .
225
+ In order to create your own custom mail solution, you need to create 2 classes: one for the ` Mailer ` and
226
+ another one for the ` Message ` .
228
227
You can use ` yii\mail\BaseMailer ` and ` yii\mail\BaseMessage ` as the base classes for your solution. These classes
229
228
already contain the basic logic, which is described in this guide. However, their usage is not mandatory, it is enough
230
229
to implement ` yii\mail\MailerInterface ` and ` yii\mail\MessageInterface ` interfaces.
0 commit comments