summaryrefslogtreecommitdiff
path: root/app/frontend/mail/Mailer.php
blob: 3b955687c1bfdf0ab9cb33a3e3746b492d6c5a62 (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
36
37
38
39
40
41
<?php

Prado::using('Lib.phpmailer.PHPMailerAutoload');
Prado::using('Application.mail.MailTemplate');

class Mailer extends PHPMailer {

    public function __construct() {
        $this->isSMTP();
        $this->SMTPAuth = TRUE;
    }

    public function configure($config) {
        $this->Host = $config->smtp->host;
        $this->Port = $config->smtp->port;
        $this->Username = $config->smtp->user;
        $this->Password = $config->smtp->pass;
        if ($config->smtp->tls) {
            $this->SMTPSecure = 'tls';
        }
        $this->setFrom($config->mail->from, $config->mail->name);
        if ($config->mail->send_copies) {
            $this->addBCC($config->mail->from);
        }
    }

    public function sendTemplate(MailTemplate $template, string $subject, string $to, string $name) {
        $this->addAddress($to, $name);
        $this->isHTML(TRUE);
        $this->Subject = $subject;
        $html = $template->execute();
        $this->Body = $html;
        $this->AltBody = strip_tags($html);
        $result = $this->send();
        $this->clearAddresses();
        return $result;
    }

}

?>