summaryrefslogtreecommitdiff
path: root/src/Mail/EngelsystemMailer.php
blob: 17047cc815f1358622656c9b95b232eb03eee9a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php

namespace Engelsystem\Mail;

use Engelsystem\Renderer\Renderer;
use Swift_Mailer as SwiftMailer;

class EngelsystemMailer extends Mailer
{
    /** @var Renderer|null */
    protected $view;

    public function __construct(SwiftMailer $mailer, Renderer $view = null)
    {
        parent::__construct($mailer);

        $this->view = $view;
    }

    /**
     * Send a template
     *
     * @param string $to
     * @param string $subject
     * @param string $template
     * @param array  $data
     * @return int
     */
    public function sendView($to, $subject, $template, $data = []): int
    {
        $body = $this->view->render($template, $data);

        return $this->send($to, $subject, $body);
    }
}