-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- PSR-2 - Configuration improvement
- Loading branch information
vanchelo
committed
Sep 7, 2015
1 parent
88645c3
commit 449e267
Showing
6 changed files
with
181 additions
and
148 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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
phalcon-mailer | ||
Phalcon Mailer | ||
============== | ||
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/vanchelo/phalcon-mailer/trend.png)](https://bitdeli.com/free "Bitdeli Badge") | ||
|
||
Сервис для отправки почты для Phalcon используя Swift Mailer. | ||
Удобная библиотека для отправки Вашей почты в [Phalcon](http://phalconphp.com/). | ||
|
||
Код заимствован из Laravel 4 и адаптирован под Phalcon. | ||
|
||
##Установка | ||
C помощью `composer`: | ||
Добавить в файл `composer.json` в секцию `require`: | ||
|
||
Добавить в файл `composer.json` в секцию `require` следующую строку: | ||
``` | ||
"vanchelo/phalcon-mailer": "dev-master" | ||
``` | ||
|
@@ -20,7 +19,10 @@ C помощью `composer`: | |
} | ||
} | ||
``` | ||
В терминале выполнить команду `composer update` | ||
После этого выполните в терминале команду: | ||
```bash | ||
composer update | ||
``` | ||
|
||
Инициализация сервиса | ||
--------- | ||
|
@@ -34,6 +36,32 @@ $this->di['mailer'] = function() { | |
return $service->mailer(); | ||
}; | ||
``` | ||
или с передачей параметров на этапе инициализации сервиса | ||
|
||
```php | ||
/** | ||
* Register Mailer Service | ||
*/ | ||
$this->di['mailer'] = function() { | ||
$service = new MailerService([ | ||
'driver' => 'smtp', // mail, sendmail, smtp | ||
'host' => 'smtp.email.com', | ||
'port' => 587, | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'My Cool Company', | ||
], | ||
'encryption' => 'tls', | ||
'username' => '[email protected]', | ||
'password' => 'some-strong-password', | ||
'sendmail' => '/usr/sbin/sendmail -bs', | ||
// Путь используемый для поиска шаблонов писем | ||
'viewsDir' => __DIR__ . '/../app/views/', // optional | ||
]); | ||
|
||
return $service->mailer(); | ||
}; | ||
``` | ||
|
||
Отправка письма | ||
--------- | ||
|
@@ -55,27 +83,23 @@ $this->mailer->send('emails/xxx', [ | |
Настройки по умолчанию необходимо прописать в конфигурационном файле вашего приложения config/config.php | ||
```php | ||
<?php | ||
return new \Phalcon\Config(array( | ||
'application' => array( | ||
// Путь используемый для поиска шаблонов писем | ||
'viewsDir' => __DIR__ . '/../app/views/', | ||
/* ... */ | ||
), | ||
|
||
'mail' => array( | ||
return new \Phalcon\Config([ | ||
'mail' => [ | ||
'driver' => 'smtp', // mail, sendmail, smtp | ||
'host' => 'smtp.email.com', | ||
'port' => 587, | ||
'from' => array( | ||
'from' => [ | ||
'address' => '[email protected]', | ||
'name' => 'My Cool Company' | ||
), | ||
], | ||
'encryption' => 'tls', | ||
'username' => '[email protected]', | ||
'password' => 'some-strong-password', | ||
'sendmail' => '/usr/sbin/sendmail -bs', | ||
), | ||
)); | ||
// Путь используемый для поиска шаблонов писем | ||
'viewsDir' => __DIR__ . '/../app/views/', // optional | ||
], | ||
]); | ||
``` | ||
|
||
Если будет необходимость, настройки почты можно вынести в отдельный конфигурационный файл | ||
|
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
Oops, something went wrong.