-
-
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
324ba56
commit d046f9d
Showing
4 changed files
with
67 additions
and
7 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 |
---|---|---|
|
@@ -12,6 +12,39 @@ | |
use yii1tech\mailer\transport\ArrayTransport; | ||
|
||
/** | ||
* Mailer allows email sending. | ||
* | ||
* Application configuration example: | ||
* | ||
* ``` | ||
* return [ | ||
* 'components' => [ | ||
* 'mailer' => [ | ||
* 'class' => yii1tech\mailer\Mailer, | ||
* 'dsn' => 'smtp://user:[email protected]:25', | ||
* 'view' => [ | ||
* 'layout' => 'default-layout', | ||
* ], | ||
* ], | ||
* ], | ||
* // ... | ||
* ]; | ||
* ``` | ||
* | ||
* Usage example: | ||
* | ||
* ``` | ||
* use Symfony\Component\Mime\Email; | ||
* | ||
* $email = (new Email()) | ||
* ->addFrom('[email protected]') | ||
* ->addTo('[email protected]') | ||
* ->subject('Test subject') | ||
* ->text('Test body'); | ||
* | ||
* Yii::app()->mailer->send($email); | ||
* ``` | ||
* | ||
* @see https://symfony.com/doc/current/mailer.html | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
|
@@ -57,10 +90,15 @@ class Mailer extends CApplicationComponent | |
/** | ||
* @var \yii1tech\mailer\View|array view instance or its array configuration. | ||
*/ | ||
private $_view = [ | ||
'class' => View::class, | ||
]; | ||
private $_view = []; | ||
|
||
/** | ||
* Sends the given message. | ||
* | ||
* @param \Symfony\Component\Mime\RawMessage|\Symfony\Component\Mime\Email|\yii1tech\mailer\TemplatedEmailContract $message message to be sent. | ||
* @param \Symfony\Component\Mailer\Envelope|null $envelope envelope instance. | ||
* @return void | ||
*/ | ||
public function send(RawMessage $message, ?Envelope $envelope = null): void | ||
{ | ||
foreach ($this->defaultHeaders as $name => $value) { | ||
|
@@ -160,7 +198,12 @@ protected function createTransport($config): TransportInterface | |
public function getView() | ||
{ | ||
if (!is_object($this->_view)) { | ||
$this->_view = Yii::createComponent($this->_view); | ||
$config = $this->_view; | ||
if (is_array($config) && !isset($config['class'])) { | ||
$config['class'] = View::class; | ||
} | ||
|
||
$this->_view = Yii::createComponent($config); | ||
} | ||
|
||
return $this->_view; | ||
|
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 |
---|---|---|
|
@@ -7,6 +7,21 @@ | |
/** | ||
* TemplatedEmail allows specification of the email body parts as a rendering of the templates. | ||
* | ||
* Usage example: | ||
* | ||
* ``` | ||
* $email = (new TemplatedEmail()) | ||
* ->addTo('[email protected]') | ||
* ->subject('Greetings') | ||
* ->textTemplate('greetings-text') | ||
* ->htmlTemplate('greetings-html') | ||
* ->context([ | ||
* 'name' => 'John Doe', | ||
* ]); | ||
* | ||
* Yii::app()->mailer->send($email); | ||
* ``` | ||
* | ||
* @see \yii1tech\mailer\View | ||
* | ||
* @author Paul Klimov <[email protected]> | ||
|
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
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