From 5308f5011ab521e6ca50427a623b69271ce22a21 Mon Sep 17 00:00:00 2001 From: Paul Klimov Date: Fri, 10 May 2024 12:01:51 +0300 Subject: [PATCH] add docs --- README.md | 116 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Mailer.php | 4 +- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a79723b..b18d047 100644 --- a/README.md +++ b/README.md @@ -38,4 +38,118 @@ to the "require" section of your composer.json. Usage ----- -This extension \ No newline at end of file +This extension provides integration of [Symfony Mailer](https://symfony.com/doc/current/mailer.html) in the Yii1 application. +Application configuration example: + +```php + [ + 'mailer' => [ + 'class' => yii1tech\mailer\Mailer, + 'dsn' => 'smtp://user:pass@smtp.example.com:25', + ], + ], + // ... +]; +``` + +Usage example: + +```php +addFrom('noreply@example.com') + ->addTo('johndoe@example.com') + ->subject('Greetings') + ->text('Welcome to our application') + ->html('

Welcome to our application

'); + +Yii::app()->mailer->send($email); +``` + + +### Configuring Emails Globally + +Application configuration example: + +```php + [ + 'mailer' => [ + 'class' => yii1tech\mailer\Mailer, + 'defaultHeaders' => [ + 'From' => 'My Application', + 'Bcc' => 'test-via-bcc@example.com', + 'X-Custom-Header' => 'foobar', + ], + // ... + ], + ], + // ... +]; +``` + + +### Template rendering + +```php +addFrom('noreply@example.com') + ->addTo('johndoe@example.com') + ->subject('Greetings') + ->textTemplate('greetings-text') + ->htmlTemplate('greetings-html') + ->context([ + 'name' => 'John Doe', + ]); + +Yii::app()->mailer->send($email); +``` + + +### Writing unit tests + +```php + [ + 'mailer' => [ + 'class' => yii1tech\mailer\Mailer, + 'dsn' => 'array://', + // ... + ], + ], + // ... +]; +``` + +```php +mailer->getTransport()->getLastSentMessage(); + + $this->assetNotNull($sentMessage); + $this->assertSame('johndoe@example.com', $sentMessage->getTo()[0]->getAddress()); + // ... + } +} +``` diff --git a/src/Mailer.php b/src/Mailer.php index 0e95a9e..edbf220 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -73,8 +73,8 @@ class Mailer extends CApplicationComponent * * ``` * [ - * 'From' => 'My App', - * 'Bcc' => 'test-bcc@example.com', + * 'From' => 'My Application', + * 'Bcc' => 'test-via-bcc@example.com', * 'X-Custom-Header' => 'foobar', * ] * ```