Create mail class

Once you have registered mailing extension, you can create new mail class and then get MailFactory from DIC to send it:

namespace App;

use Nette,

class ContactMail extends Mail implements IComposableMail

	 * There you will always have your mail addresses from configuration file
	 * @var array
	protected $mails;

	public function compose(Nette\Mail\Message $message, $params = NULL)

use Nette,

class HomepagePresenter extends Nette\Application\UI\Presenter

     * @var Ublaboo\Mailing\MailFactory
     * @inject
    public $mailFactory;

    public function actionDefault()
        $params = ['recipient' => 'hello@hello.hello'];
        $mail = $this->mailFactory->createByType('App\Mailing\ContactMail', $params);


Send it!

No comment, see an example:

# ...

$mail = $this->mailFactory->createByType('App\Mailing\ContactMail', $params);

Pass parameters

You see the $params variable? That variable is passed to the ::compose method of you mail class. And also it is passed into mail template, exapanded of course. So, say you pass parameters (below) to $mailFactory, you will be able to use $recipient and $name in your mail template.

$params = [
    'recipient' => 'john@doe.example',
    'name' => 'John Doe'

Example mail template:

<!DOCTYPE html>
		<title>Contact mail</title>
	    Helo, {$name}
	    Your email is: {$recipient}

Continue to templates.

Tento web používá k poskytování služeb a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. V pořádku Další informace