flame / email-package
Basic classes for working with Emails on Nette
v2.1.0
2014-07-05 09:16 UTC
Requires
- php: >=5.3.2
- nette/nette: >=2.0.1
This package is not auto-updated.
Last update: 2024-11-09 15:08:17 UTC
README
Advanced emails with custom templates on Nette
###Instalation
Install the package via composer.
Add into your dependencies: "flame/email-package": ">=2.0.0"
Register emails extension
\Flame\Email\DI\EmailsExtension::register($configurator);
Configure emails via config
emails: support: [sifalda.jiri@gmail.com, Support]
From this configuration will be created object of Flame\Email\EmailAddress which will be added into Flame\Email\EmailAddressContainer.
##Example of usage Create custom email
use Enlan\UserModule\Entity\User; use Flame\Email\EmailAddress; use Flame\Email\IEmailFactory; use Flame\Email\IFullMessageFactory; use Nette\Object; class Mailer extends Object { /** @var IEmailFactory */ private $emailFactory; /** @var IFullMessageFactory */ private $messageFactory; /** * @param IEmailFactory $emailFactory * @param IFullMessageFactory $messageFactory */ function __construct(IEmailFactory $emailFactory, IFullMessageFactory $messageFactory) { $this->emailFactory = $emailFactory; $this->messageFactory = $messageFactory; } /** * @param User $user */ public function sendEmailsOnCreate(User $user) { $message = $this->messageFactory ->addTo(new EmailAddress($user->getEmail(), $user->getIdentifier())) ->setFrom('support') ->createMessage() ->setSubject('Hello'); $email = $this->emailFactory ->createEmail() ->setMessage($message) ->setTemplateFile(__DIR__ . '/../templates/NewUserEmail.latte'); $email->template->greeting = 'Hi, all!'; $email->send(); } }
Template file
<h3>Greeting</h3> <p>{$greeting}</p> <a href="{plink //Homepage: }" target="_blank">Visit homepage</a>
Now, you can use Mailer for sending your advanced Nette emails :-)