-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be1f470
commit 5308f50
Showing
2 changed files
with
117 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,118 @@ to the "require" section of your composer.json. | |
Usage | ||
----- | ||
|
||
This extension | ||
This extension provides integration of [Symfony Mailer](https://symfony.com/doc/current/mailer.html) in the Yii1 application. | ||
Application configuration example: | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'components' => [ | ||
'mailer' => [ | ||
'class' => yii1tech\mailer\Mailer, | ||
'dsn' => 'smtp://user:[email protected]:25', | ||
], | ||
], | ||
// ... | ||
]; | ||
``` | ||
|
||
Usage example: | ||
|
||
```php | ||
<?php | ||
|
||
use Symfony\Component\Mime\Email; | ||
|
||
$email = (new Email()) | ||
->addFrom('[email protected]') | ||
->addTo('[email protected]') | ||
->subject('Greetings') | ||
->text('Welcome to our application') | ||
->html('<h1>Welcome to our application</h1>'); | ||
|
||
Yii::app()->mailer->send($email); | ||
``` | ||
|
||
|
||
### Configuring Emails Globally <span id="configuring-emails-globally"></span> | ||
|
||
Application configuration example: | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'components' => [ | ||
'mailer' => [ | ||
'class' => yii1tech\mailer\Mailer, | ||
'defaultHeaders' => [ | ||
'From' => 'My Application<noreply@example.com>', | ||
'Bcc' => '[email protected]', | ||
'X-Custom-Header' => 'foobar', | ||
], | ||
// ... | ||
], | ||
], | ||
// ... | ||
]; | ||
``` | ||
|
||
|
||
### Template rendering <span id="template-rendering"></span> | ||
|
||
```php | ||
<?php | ||
|
||
use yii1tech\mailer\TemplatedEmail; | ||
|
||
$email = (new TemplatedEmail()) | ||
->addFrom('[email protected]') | ||
->addTo('[email protected]') | ||
->subject('Greetings') | ||
->textTemplate('greetings-text') | ||
->htmlTemplate('greetings-html') | ||
->context([ | ||
'name' => 'John Doe', | ||
]); | ||
|
||
Yii::app()->mailer->send($email); | ||
``` | ||
|
||
|
||
### Writing unit tests <span id="writing-unit-tests"></span> | ||
|
||
```php | ||
<?php | ||
|
||
return [ | ||
'components' => [ | ||
'mailer' => [ | ||
'class' => yii1tech\mailer\Mailer, | ||
'dsn' => 'array://', | ||
// ... | ||
], | ||
], | ||
// ... | ||
]; | ||
``` | ||
|
||
```php | ||
<?php | ||
|
||
class MailTest extends TestCase | ||
{ | ||
public function testMail(): void | ||
{ | ||
// code under test here | ||
|
||
/** @var \Symfony\Component\Mime\Email $sentMessage */ | ||
$sentMessage = Yii::app()->mailer->getTransport()->getLastSentMessage(); | ||
|
||
$this->assetNotNull($sentMessage); | ||
$this->assertSame('[email protected]', $sentMessage->getTo()[0]->getAddress()); | ||
// ... | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,8 +73,8 @@ class Mailer extends CApplicationComponent | |
* | ||
* ``` | ||
* [ | ||
* 'From' => 'My App<[email protected]>', | ||
* 'Bcc' => '[email protected]', | ||
* 'From' => 'My Application<[email protected]>', | ||
* 'Bcc' => 'test-via-[email protected]', | ||
* 'X-Custom-Header' => 'foobar', | ||
* ] | ||
* ``` | ||
|