@ -21,7 +21,7 @@ In general your application configuration should look like:
return [
//....
'components' => [
'mail' => [
'mailer ' => [
'class' => 'yii\swiftmailer\Mailer',
],
],
@ -32,10 +32,10 @@ return [
Basic usage
-----------
Once 'mail' component is configured, you can use the following code to send an email message:
Once 'mailer ' component is configured, you can use the following code to send an email message:
```php
Yii::$app->mail->compose()
Yii::$app->mailer ->compose()
->setFrom('from@domain.com')
->setTo('to@domain.com')
->setSubject('Message subject')
@ -48,7 +48,7 @@ In above example method `compose()` creates an instance of the mail message, whi
You may put more complex logic in this process if needed:
```php
$message = Yii::$app->mail->compose();
$message = Yii::$app->mailer ->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('from@domain.com')
} else {
@ -60,7 +60,7 @@ $message->setTo(Yii::$app->params['adminEmail'])
->send();
```
> Note: each 'mail' extension comes in 2 major classes: 'Mailer' and 'Message'. 'Mailer' always knows
> Note: each 'mailer ' extension comes in 2 major classes: 'Mailer' and 'Message'. 'Mailer' always knows
the class name and specific of the 'Message'. Do not attempt ot instantiate 'Message' object directly -
always use `compose()` method for it.
@ -69,11 +69,11 @@ You may also send several messages at once:
```php
$messages = [];
foreach ($users as $user) {
$messages[] = Yii::$app->mail->compose()
$messages[] = Yii::$app->mailer ->compose()
// ...
->setTo($user->email);
}
Yii::$app->mail->sendMultiple($messages);
Yii::$app->mailer ->sendMultiple($messages);
```
Some particular mail extensions may benefit from this approach, using single network message etc.
@ -104,7 +104,7 @@ use yii\helpers\Url;
In order to compose message content via view file simply pass view name to the `compose()` method:
```php
Yii::$app->mail->compose('home-link') // message body becomes a view rendering result here
Yii::$app->mailer ->compose('home-link') // message body becomes a view rendering result here
->setFrom('from@domain.com')
->setTo('to@domain.com')
->setSubject('Message subject')
@ -114,7 +114,7 @@ Yii::$app->mail->compose('home-link') // message body becomes a view rendering r
You may pass additional view parameters to `compose()` method, which will be available inside the view files:
```php
Yii::$app->mail->compose('greetings', [
Yii::$app->mailer ->compose('greetings', [
'user' => Yii::$app->user->identity,
'advertisement' => $adContent,
]);
@ -123,7 +123,7 @@ Yii::$app->mail->compose('greetings', [
You can specify different view files for HTML and plain text message contents:
```php
Yii::$app->mail->compose([
Yii::$app->mailer ->compose([
'html' => 'contact-html',
'text' => 'contact-text',
]);
@ -172,7 +172,7 @@ File attachment
You can add attachments to message using methods `attach()` and `attachContent()` :
```php
$message = Yii::$app->mail->compose();
$message = Yii::$app->mailer ->compose();
// Attach file from local file system:
$message->attach('/path/to/source/file.pdf');
@ -190,7 +190,7 @@ which should be then used at 'img' tag.
This method is easy to use when composing message content via view file:
```php
Yii::$app->mail->compose('embed-email', ['imageFileName' => '/path/to/image.jpg'])
Yii::$app->mailer ->compose('embed-email', ['imageFileName' => '/path/to/image.jpg'])
// ...
->send();
```