Mailer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A send() 0 13 2
1
<?php
2
3
namespace Lepton\Core;
4
5
use PHPMailer\PHPMailer\PHPMailer;
6
use Lepton\Core\Application;
7
8
class Mailer
9
{
10
    private $mailer;
11
    public $error;
12
13
    public function __construct()
14
    {
15
        $config = Application::getEmailConfig();
16
        $this->mailer = new PHPMailer();
17
        $this->mailer->isSMTP();
18
        //$this->mailer->SMTPDebug = SMTP::DEBUG_SERVER;
19
20
        $this->mailer->Host = $config->host;
21
        $this->mailer->Port = 465;
22
        $this->mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
23
        $this->mailer->setFrom($config->username, $config->fromName);
24
        $this->mailer->SMTPAuth = true;
25
        $this->mailer->Username = $config->username;
26
        $this->mailer->Password = $config->password;
27
        $this->mailer->addReplyTo($config->replyTo, $config->replyToName);
28
    }
29
30
    public function send($to, $subject, $body, $attachments=array())
31
    {
32
        $this->mailer->addAddress($to);
33
        $this->mailer->Subject = $subject;
34
        $this->mailer->msgHTML($body);
35
        foreach ($attachments as $att) {
36
            $file = $_SERVER['DOCUMENT_ROOT'].Application::getDir()."/resources/".$att;
37
            $this->mailer->addAttachment($file);
38
        }
39
40
        $sent = $this->mailer->send();
41
        $this->error = $this->mailer->ErrorInfo;
42
        return $sent;
43
    }
44
}
45