|
|
|
@ -97,14 +97,14 @@ use yii\helpers\Url;
|
|
|
|
|
/* @var $message \yii\mail\BaseMessage instance of newly created mail message */ |
|
|
|
|
|
|
|
|
|
?> |
|
|
|
|
<h2>This message allows you to visit out site home page by one click</h2> |
|
|
|
|
<h2>This message allows you to visit our site home page by one click</h2> |
|
|
|
|
<?= Html::a('Go to home page', Url::home('http')) ?> |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
In order to compose message content via view file simply pass view name to the `compose()` method: |
|
|
|
|
|
|
|
|
|
```php |
|
|
|
|
Yii::$app->mailer->compose('home-link') // message body becomes a view rendering result here |
|
|
|
|
Yii::$app->mailer->compose('home-link') // a view rendering result becomes the message body here |
|
|
|
|
->setFrom('from@domain.com') |
|
|
|
|
->setTo('to@domain.com') |
|
|
|
|
->setSubject('Message subject') |
|
|
|
@ -183,8 +183,8 @@ $message->attachContent('Attachment content', ['fileName' => 'attach.txt', 'cont
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Embed images |
|
|
|
|
------------ |
|
|
|
|
Embedding images |
|
|
|
|
---------------- |
|
|
|
|
|
|
|
|
|
You can embed images into the message content using `embed()` method. This method returns the attachment id, |
|
|
|
|
which should be then used at 'img' tag. |
|
|
|
@ -196,7 +196,7 @@ Yii::$app->mailer->compose('embed-email', ['imageFileName' => '/path/to/image.jp
|
|
|
|
|
->send(); |
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
Then inside view file you can use following code: |
|
|
|
|
Then inside the view file you can use the following code: |
|
|
|
|
|
|
|
|
|
```php |
|
|
|
|
<img src="<?= $message->embed($imageFileName); ?>"> |
|
|
|
@ -206,17 +206,17 @@ Then inside view file you can use following code:
|
|
|
|
|
Testing and debugging |
|
|
|
|
--------------------- |
|
|
|
|
|
|
|
|
|
Developer often a to check, what actual emails are sent by application, what was their content and so on. |
|
|
|
|
A developer often has to check, what actual emails are sent by the application, what was their content and so on. |
|
|
|
|
Such ability is granted by Yii via `yii\mail\BaseMailer::useFileTransport`. If enabled, this option enforces |
|
|
|
|
saving mail message data into the local files instead of regular sending. These files will be saved under |
|
|
|
|
`yii\mail\BaseMailer::fileTransportPath`, which is '@runtime/mail' by default. |
|
|
|
|
|
|
|
|
|
> Note: you can either save messages to the file or send them to actual recipients, but can not do both simultaneously. |
|
|
|
|
> Note: you can either save the messages to the files or send them to the actual recipients, but can not do both simultaneously. |
|
|
|
|
|
|
|
|
|
Mail message file can be opened by regular text file editor, so you can browse actual message headers, content and so on. |
|
|
|
|
This mechanism amy prove itself, while debugging application or running unit test. |
|
|
|
|
A mail message file can be opened by a regular text file editor, so you can browse the actual message headers, content and so on. |
|
|
|
|
This mechanism may prove itself, while debugging application or running unit test. |
|
|
|
|
|
|
|
|
|
> Note: mail message file content is composed via `\yii\mail\MessageInterface::toString()`, so it depends on actual |
|
|
|
|
> Note: the mail message file content is composed via `\yii\mail\MessageInterface::toString()`, so it depends on the actual |
|
|
|
|
mail extension you are using in your application. |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -225,7 +225,7 @@ Creating your own mail solution
|
|
|
|
|
|
|
|
|
|
In order to create your own custom mail solution, you need to create 2 classes: one for the 'Mailer' and |
|
|
|
|
another one for the 'Message'. |
|
|
|
|
You can use `yii\mail\BaseMailer` and `yii\mail\BaseMessage` as a base classes for your solution. These classes |
|
|
|
|
already contains basic logic, which is described in this guide. However, their usage is not mandatory, it is enough |
|
|
|
|
You can use `yii\mail\BaseMailer` and `yii\mail\BaseMessage` as the base classes for your solution. These classes |
|
|
|
|
already contain the basic logic, which is described in this guide. However, their usage is not mandatory, it is enough |
|
|
|
|
to implement `yii\mail\MailerInterface` and `yii\mail\MessageInterface` interfaces. |
|
|
|
|
Then you need to implement all abstract methods to build you solution. |
|
|
|
|
Then you need to implement all the abstract methods to build your solution. |
|
|
|
|