GithubHelp home page GithubHelp logo

email-package's Introduction

Email Package

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: [[email protected], 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 :-)

email-package's People

Contributors

jsifalda avatar

Stargazers

Vojtěch Dobeš avatar Pavel Lauko avatar  avatar Michal Gebauer avatar Pavel Bier avatar

Watchers

Vojtěch Dobeš avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.