mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 11:10:36 +08:00
Fixes #4071: mail component renamed to mailer, yii\log\EmailTarget::$mail renamed to yii\log\EmailTarget::$mailer
This commit is contained in:
@@ -8,7 +8,7 @@ return [
|
|||||||
'password' => '',
|
'password' => '',
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
'viewPath' => '@common/mail',
|
'viewPath' => '@common/mail',
|
||||||
// send all mails to a file by default. You have to set
|
// send all mails to a file by default. You have to set
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ return [
|
|||||||
'password' => '',
|
'password' => '',
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
'viewPath' => '@common/mail',
|
'viewPath' => '@common/mail',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ContactForm extends Model
|
|||||||
*/
|
*/
|
||||||
public function sendEmail($email)
|
public function sendEmail($email)
|
||||||
{
|
{
|
||||||
return Yii::$app->mail->compose()
|
return Yii::$app->mailer->compose()
|
||||||
->setTo($email)
|
->setTo($email)
|
||||||
->setFrom([$this->email => $this->name])
|
->setFrom([$this->email => $this->name])
|
||||||
->setSubject($this->subject)
|
->setSubject($this->subject)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class PasswordResetRequestForm extends Model
|
|||||||
if ($user) {
|
if ($user) {
|
||||||
$user->generatePasswordResetToken();
|
$user->generatePasswordResetToken();
|
||||||
if ($user->save()) {
|
if ($user->save()) {
|
||||||
return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user])
|
return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])
|
||||||
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
|
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
|
||||||
->setTo($this->email)
|
->setTo($this->email)
|
||||||
->setSubject('Password reset for ' . \Yii::$app->name)
|
->setSubject('Password reset for ' . \Yii::$app->name)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class ContactFormTest extends TestCase
|
|||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Yii::$app->mail->fileTransportCallback = function ($mailer, $message) {
|
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||||
return 'testing_message.eml';
|
return 'testing_message.eml';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -54,6 +54,6 @@ class ContactFormTest extends TestCase
|
|||||||
|
|
||||||
private function getMessageFile()
|
private function getMessageFile()
|
||||||
{
|
{
|
||||||
return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml';
|
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class PasswordResetRequestFormTest extends DbTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Yii::$app->mail->fileTransportCallback = function ($mailer, $message) {
|
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||||
return 'testing_message.eml';
|
return 'testing_message.eml';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ class PasswordResetRequestFormTest extends DbTestCase
|
|||||||
|
|
||||||
private function getMessageFile()
|
private function getMessageFile()
|
||||||
{
|
{
|
||||||
return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml';
|
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ $config = [
|
|||||||
'errorHandler' => [
|
'errorHandler' => [
|
||||||
'errorAction' => 'site/error',
|
'errorAction' => 'site/error',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
// send all mails to a file by default. You have to set
|
// send all mails to a file by default. You have to set
|
||||||
// 'useFileTransport' to false and configure a transport
|
// 'useFileTransport' to false and configure a transport
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class ContactForm extends Model
|
|||||||
public function contact($email)
|
public function contact($email)
|
||||||
{
|
{
|
||||||
if ($this->validate()) {
|
if ($this->validate()) {
|
||||||
Yii::$app->mail->compose()
|
Yii::$app->mailer->compose()
|
||||||
->setTo($email)
|
->setTo($email)
|
||||||
->setFrom([$this->email => $this->name])
|
->setFrom([$this->email => $this->name])
|
||||||
->setSubject($this->subject)
|
->setSubject($this->subject)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class ContactFormTest extends TestCase
|
|||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Yii::$app->mail->fileTransportCallback = function ($mailer, $message) {
|
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||||
return 'testing_message.eml';
|
return 'testing_message.eml';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ class ContactFormTest extends TestCase
|
|||||||
|
|
||||||
private function getMessageFile()
|
private function getMessageFile()
|
||||||
{
|
{
|
||||||
return Yii::getAlias(Yii::$app->mail->fileTransportPath) . '/testing_message.eml';
|
return Yii::getAlias(Yii::$app->mailer->fileTransportPath) . '/testing_message.eml';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
<p>
|
<p>
|
||||||
Note that if you turn on the Yii debugger, you should be able
|
Note that if you turn on the Yii debugger, you should be able
|
||||||
to view the mail message on the mail panel of the debugger.
|
to view the mail message on the mail panel of the debugger.
|
||||||
<?php if (Yii::$app->mail->useFileTransport): ?>
|
<?php if (Yii::$app->mailer->useFileTransport): ?>
|
||||||
Because the application is in development mode, the email is not sent but saved as
|
Because the application is in development mode, the email is not sent but saved as
|
||||||
a file under <code><?= Yii::getAlias(Yii::$app->mail->fileTransportPath) ?></code>.
|
a file under <code><?= Yii::getAlias(Yii::$app->mailer->fileTransportPath) ?></code>.
|
||||||
Please configure the <code>useFileTransport</code> property of the <code>mail</code>
|
Please configure the <code>useFileTransport</code> property of the <code>mail</code>
|
||||||
application component to be false to enable email sending.
|
application component to be false to enable email sending.
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ $config = [
|
|||||||
'cache' => [
|
'cache' => [
|
||||||
'class' => 'yii\caching\FileCache',
|
'class' => 'yii\caching\FileCache',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
'log' => [
|
'log' => [
|
||||||
@@ -191,7 +191,7 @@ return [
|
|||||||
'cache' => [
|
'cache' => [
|
||||||
'class' => 'yii\caching\FileCache',
|
'class' => 'yii\caching\FileCache',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
'log' => [
|
'log' => [
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ $config = [
|
|||||||
'cache' => [
|
'cache' => [
|
||||||
'class' => 'yii\caching\FileCache',
|
'class' => 'yii\caching\FileCache',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
'log' => [
|
'log' => [
|
||||||
@@ -184,7 +184,7 @@ return [
|
|||||||
'cache' => [
|
'cache' => [
|
||||||
'class' => 'yii\caching\FileCache',
|
'class' => 'yii\caching\FileCache',
|
||||||
],
|
],
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
'log' => [
|
'log' => [
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ In general your application configuration should look like:
|
|||||||
return [
|
return [
|
||||||
//....
|
//....
|
||||||
'components' => [
|
'components' => [
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -32,10 +32,10 @@ return [
|
|||||||
Basic usage
|
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
|
```php
|
||||||
Yii::$app->mail->compose()
|
Yii::$app->mailer->compose()
|
||||||
->setFrom('from@domain.com')
|
->setFrom('from@domain.com')
|
||||||
->setTo('to@domain.com')
|
->setTo('to@domain.com')
|
||||||
->setSubject('Message subject')
|
->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:
|
You may put more complex logic in this process if needed:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$message = Yii::$app->mail->compose();
|
$message = Yii::$app->mailer->compose();
|
||||||
if (Yii::$app->user->isGuest) {
|
if (Yii::$app->user->isGuest) {
|
||||||
$message->setFrom('from@domain.com')
|
$message->setFrom('from@domain.com')
|
||||||
} else {
|
} else {
|
||||||
@@ -60,7 +60,7 @@ $message->setTo(Yii::$app->params['adminEmail'])
|
|||||||
->send();
|
->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 -
|
the class name and specific of the 'Message'. Do not attempt ot instantiate 'Message' object directly -
|
||||||
always use `compose()` method for it.
|
always use `compose()` method for it.
|
||||||
|
|
||||||
@@ -69,11 +69,11 @@ You may also send several messages at once:
|
|||||||
```php
|
```php
|
||||||
$messages = [];
|
$messages = [];
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$messages[] = Yii::$app->mail->compose()
|
$messages[] = Yii::$app->mailer->compose()
|
||||||
// ...
|
// ...
|
||||||
->setTo($user->email);
|
->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.
|
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:
|
In order to compose message content via view file simply pass view name to the `compose()` method:
|
||||||
|
|
||||||
```php
|
```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')
|
->setFrom('from@domain.com')
|
||||||
->setTo('to@domain.com')
|
->setTo('to@domain.com')
|
||||||
->setSubject('Message subject')
|
->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:
|
You may pass additional view parameters to `compose()` method, which will be available inside the view files:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Yii::$app->mail->compose('greetings', [
|
Yii::$app->mailer->compose('greetings', [
|
||||||
'user' => Yii::$app->user->identity,
|
'user' => Yii::$app->user->identity,
|
||||||
'advertisement' => $adContent,
|
'advertisement' => $adContent,
|
||||||
]);
|
]);
|
||||||
@@ -123,7 +123,7 @@ Yii::$app->mail->compose('greetings', [
|
|||||||
You can specify different view files for HTML and plain text message contents:
|
You can specify different view files for HTML and plain text message contents:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Yii::$app->mail->compose([
|
Yii::$app->mailer->compose([
|
||||||
'html' => 'contact-html',
|
'html' => 'contact-html',
|
||||||
'text' => 'contact-text',
|
'text' => 'contact-text',
|
||||||
]);
|
]);
|
||||||
@@ -172,7 +172,7 @@ File attachment
|
|||||||
You can add attachments to message using methods `attach()` and `attachContent()`:
|
You can add attachments to message using methods `attach()` and `attachContent()`:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$message = Yii::$app->mail->compose();
|
$message = Yii::$app->mailer->compose();
|
||||||
|
|
||||||
// Attach file from local file system:
|
// Attach file from local file system:
|
||||||
$message->attach('/path/to/source/file.pdf');
|
$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:
|
This method is easy to use when composing message content via view file:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Yii::$app->mail->compose('embed-email', ['imageFileName' => '/path/to/image.jpg'])
|
Yii::$app->mailer->compose('embed-email', ['imageFileName' => '/path/to/image.jpg'])
|
||||||
// ...
|
// ...
|
||||||
->send();
|
->send();
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ class MailTest extends TestCase
|
|||||||
// don't forget to call parent method that will setup Yii application
|
// don't forget to call parent method that will setup Yii application
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Yii::$app->mail->fileTransportCallback = function ($mailer, $message) {
|
Yii::$app->mailer->fileTransportCallback = function ($mailer, $message) {
|
||||||
return 'testing_message.eml';
|
return 'testing_message.eml';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use yii\mail\BaseMailer;
|
|||||||
* ~~~
|
* ~~~
|
||||||
* 'components' => [
|
* 'components' => [
|
||||||
* ...
|
* ...
|
||||||
* 'mail' => [
|
* 'mailer' => [
|
||||||
* 'class' => 'yii\swiftmailer\Mailer',
|
* 'class' => 'yii\swiftmailer\Mailer',
|
||||||
* 'transport' => [
|
* 'transport' => [
|
||||||
* 'class' => 'Swift_SmtpTransport',
|
* 'class' => 'Swift_SmtpTransport',
|
||||||
@@ -57,7 +57,7 @@ use yii\mail\BaseMailer;
|
|||||||
* To send an email, you may use the following code:
|
* To send an email, you may use the following code:
|
||||||
*
|
*
|
||||||
* ~~~
|
* ~~~
|
||||||
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
|
* Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
|
||||||
* ->setFrom('from@domain.com')
|
* ->setFrom('from@domain.com')
|
||||||
* ->setTo($form->email)
|
* ->setTo($form->email)
|
||||||
* ->setSubject($form->subject)
|
* ->setSubject($form->subject)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ To use this extension, simply add the following code in your application config
|
|||||||
return [
|
return [
|
||||||
//....
|
//....
|
||||||
'components' => [
|
'components' => [
|
||||||
'mail' => [
|
'mailer' => [
|
||||||
'class' => 'yii\swiftmailer\Mailer',
|
'class' => 'yii\swiftmailer\Mailer',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
@@ -19,7 +19,7 @@ return [
|
|||||||
You can then send an email as follows:
|
You can then send an email as follows:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
Yii::$app->mail->compose('contact/html')
|
Yii::$app->mailer->compose('contact/html')
|
||||||
->setFrom('from@domain.com')
|
->setFrom('from@domain.com')
|
||||||
->setTo($form->email)
|
->setTo($form->email)
|
||||||
->setSubject($form->subject)
|
->setSubject($form->subject)
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ Yii Framework 2 Change Log
|
|||||||
- Chg #3897: Raised visibility of `yii\web\View::registerAssetFiles()` to protected (samdark)
|
- Chg #3897: Raised visibility of `yii\web\View::registerAssetFiles()` to protected (samdark)
|
||||||
- Chg #3899: Moved `MailEvent` class to `yii\mail` namespace (cebe)
|
- Chg #3899: Moved `MailEvent` class to `yii\mail` namespace (cebe)
|
||||||
- Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue)
|
- Chg #3956: Flash messages set via `Yii::$app->session->setFlash()` will be removed only if they are accessed (qiangxue)
|
||||||
|
- Chg #4071: `mail` component renamed to `mailer`, `yii\log\EmailTarget::$mail` renamed to `yii\log\EmailTarget::$mailer` (samdark)
|
||||||
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
|
- Chg: Replaced `clearAll()` and `clearAllAssignments()` in `yii\rbac\ManagerInterface` with `removeAll()`, `removeAllRoles()`, `removeAllPermissions()`, `removeAllRules()` and `removeAllAssignments()` (qiangxue)
|
||||||
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
|
- Chg: Added `$user` as the first parameter of `yii\rbac\Rule::execute()` (qiangxue)
|
||||||
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
|
- Chg: `yii\grid\DataColumn::getDataCellValue()` visibility is now `public` to allow accessing the value from a GridView directly (cebe)
|
||||||
|
|||||||
@@ -69,3 +69,6 @@ Upgrade from Yii 2.0 Beta
|
|||||||
* If you are developing RESTful APIs and using an authentication method such as `yii\filters\auth\HttpBasicAuth`,
|
* If you are developing RESTful APIs and using an authentication method such as `yii\filters\auth\HttpBasicAuth`,
|
||||||
you should explicitly configure `yii\web\User::enableSession` in the application configuration to be false to avoid
|
you should explicitly configure `yii\web\User::enableSession` in the application configuration to be false to avoid
|
||||||
starting a session when authentication is performed. Previously this was done automatically by authentication method.
|
starting a session when authentication is performed. Previously this was done automatically by authentication method.
|
||||||
|
|
||||||
|
* `mail` component was renamed to `mailer`, `yii\log\EmailTarget::$mail` was renamed to `yii\log\EmailTarget::$mailer`.
|
||||||
|
Please update all references in the code and config files.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use yii\mail\MailerInterface;
|
|||||||
* 'targets' => [
|
* 'targets' => [
|
||||||
* [
|
* [
|
||||||
* 'class' => 'yii\log\EmailTarget',
|
* 'class' => 'yii\log\EmailTarget',
|
||||||
* 'mail' =>'mail',
|
* 'mailer' =>'mailer',
|
||||||
* 'levels' => ['error', 'warning'],
|
* 'levels' => ['error', 'warning'],
|
||||||
* 'message' => [
|
* 'message' => [
|
||||||
* 'from' => ['log@example.com'],
|
* 'from' => ['log@example.com'],
|
||||||
@@ -37,7 +37,7 @@ use yii\mail\MailerInterface;
|
|||||||
* ],
|
* ],
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* In the above `mail` is ID of the component that sends email and should be already configured.
|
* In the above `mailer` is ID of the component that sends email and should be already configured.
|
||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
@@ -54,7 +54,7 @@ class EmailTarget extends Target
|
|||||||
* After the EmailTarget object is created, if you want to change this property, you should only assign it
|
* After the EmailTarget object is created, if you want to change this property, you should only assign it
|
||||||
* with a mailer object.
|
* with a mailer object.
|
||||||
*/
|
*/
|
||||||
public $mail = 'mail';
|
public $mailer = 'mailer';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,7 +66,7 @@ class EmailTarget extends Target
|
|||||||
if (empty($this->message['to'])) {
|
if (empty($this->message['to'])) {
|
||||||
throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
|
throw new InvalidConfigException('The "to" option must be set for EmailTarget::message.');
|
||||||
}
|
}
|
||||||
$this->mail = Instance::ensure($this->mail, 'yii\mail\MailerInterface');
|
$this->mailer = Instance::ensure($this->mailer, 'yii\mail\MailerInterface');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +81,7 @@ class EmailTarget extends Target
|
|||||||
}
|
}
|
||||||
$messages = array_map([$this, 'formatMessage'], $this->messages);
|
$messages = array_map([$this, 'formatMessage'], $this->messages);
|
||||||
$body = wordwrap(implode("\n", $messages), 70);
|
$body = wordwrap(implode("\n", $messages), 70);
|
||||||
$this->composeMessage($body)->send($this->mail);
|
$this->composeMessage($body)->send($this->mailer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +91,7 @@ class EmailTarget extends Target
|
|||||||
*/
|
*/
|
||||||
protected function composeMessage($body)
|
protected function composeMessage($body)
|
||||||
{
|
{
|
||||||
$message = $this->mail->compose();
|
$message = $this->mailer->compose();
|
||||||
Yii::configure($message, $this->message);
|
Yii::configure($message, $this->message);
|
||||||
$message->setTextBody($body);
|
$message->setTextBody($body);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace yii\mail;
|
|||||||
* also support composition of the message body through the view rendering mechanism. For example,
|
* also support composition of the message body through the view rendering mechanism. For example,
|
||||||
*
|
*
|
||||||
* ~~~
|
* ~~~
|
||||||
* Yii::$app->mail->compose('contact/html', ['contactForm' => $form])
|
* Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
|
||||||
* ->setFrom('from@domain.com')
|
* ->setFrom('from@domain.com')
|
||||||
* ->setTo($form->email)
|
* ->setTo($form->email)
|
||||||
* ->setSubject($form->subject)
|
* ->setSubject($form->subject)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace yii\mail;
|
|||||||
* Messages are sent by a [[\yii\mail\MailerInterface|mailer]], like the following,
|
* Messages are sent by a [[\yii\mail\MailerInterface|mailer]], like the following,
|
||||||
*
|
*
|
||||||
* ~~~
|
* ~~~
|
||||||
* Yii::$app->mail->compose()
|
* Yii::$app->mailer->compose()
|
||||||
* ->setFrom('from@domain.com')
|
* ->setFrom('from@domain.com')
|
||||||
* ->setTo($form->email)
|
* ->setTo($form->email)
|
||||||
* ->setSubject($form->subject)
|
* ->setSubject($form->subject)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class MessageTest extends VendorTestCase
|
|||||||
{
|
{
|
||||||
$this->mockApplication([
|
$this->mockApplication([
|
||||||
'components' => [
|
'components' => [
|
||||||
'mail' => $this->createTestEmailComponent()
|
'mailer' => $this->createTestEmailComponent()
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
$filePath = $this->getTestFilePath();
|
$filePath = $this->getTestFilePath();
|
||||||
@@ -68,7 +68,7 @@ class MessageTest extends VendorTestCase
|
|||||||
*/
|
*/
|
||||||
protected function createTestMessage()
|
protected function createTestMessage()
|
||||||
{
|
{
|
||||||
return Yii::$app->get('mail')->compose();
|
return Yii::$app->get('mailer')->compose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class BaseMessageTest extends TestCase
|
|||||||
{
|
{
|
||||||
$this->mockApplication([
|
$this->mockApplication([
|
||||||
'components' => [
|
'components' => [
|
||||||
'mail' => $this->createTestEmailComponent()
|
'mailer' => $this->createTestEmailComponent()
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ class BaseMessageTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected function getMailer()
|
protected function getMailer()
|
||||||
{
|
{
|
||||||
return Yii::$app->get('mail');
|
return Yii::$app->get('mailer');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests :
|
// Tests :
|
||||||
|
|||||||
Reference in New Issue
Block a user