Mail

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,
	Ublaboo\Mailing\Mail,
	Ublaboo\Mailing\IComposableMail;

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)
	{
		$message->setFrom($this->mails['default_sender']);
		$message->addTo($params['recipient']);
	}

}
use Nette,
    Ublaboo;

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);
$mail->send();

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>
	<html>
	<head>
		<title>Contact mail</title>
	</head>
	<body>
	    Helo, {$name}
	    <br>
	    Your email is: {$recipient}
	</body>
</html>

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