-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMailHandler.php
More file actions
120 lines (98 loc) · 2.48 KB
/
MailHandler.php
File metadata and controls
120 lines (98 loc) · 2.48 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Plugins\mail;
use Slim\Views\Twig;
class MailHandler
{
protected $mail;
protected $twig;
public function __construct($mail, Twig $twig)
{
$this->mail = $mail;
$this->twig = $twig;
}
public function addAdress($address, $name = '')
{
$this->mail->addAddress($address, $name);
}
public function addCC($adress, $name = '')
{
$this->mail->addCC($address, $name);
}
public function addBCC($address, $name = '')
{
$this->mail->addBCC($address, $name);
}
public function addReplyTo($address, $name = '')
{
$this->mail->addReplyTo($address, $name);
}
public function setFrom($address, $name = '')
{
$this->mail->setFrom($address, $name, $auto = true);
}
public function addCustomHeader($name, $value = null)
{
$this->mail->addCustomHeader($name, $value);
}
public function addAttachment($path, $name = '')
{
$this->mail->addAttachment($path, $name);
}
public function msgHTML($message, $basedir = '', $advanced = false)
{
$this->mail->msgHTML($message, $basedir, $advanced = false);
}
public function isHTML()
{
$this->mail->isHTML(true);
}
public function setSubject($subject)
{
$this->mail->Subject = $subject;
}
public function setBody($body)
{
$this->mail->Body = $body; // html-body
}
public function setAltBody($altbody)
{
$this->mail->AltBody = $altbody;
}
public function ClearAttachments()
{
$this->mail->clearAttachments();
}
public function ClearCustomHeaders()
{
$this->mail->clearCustomHeaders();
}
public function ClearAllRecipients()
{
$this->mail->ClearAllRecipients();
}
public function ClearMail()
{
$this->mail->ClearAllRecipients();
$this->mail->clearAttachments();
$this->mail->clearCustomHeaders();
}
public function send()
{
# create a mail-error-logger that stores error messages, maybe even displays in admin
# catch the smtp-errors this way: https://stackoverflow.com/questions/39565769/get-full-error-message-from-phpmailer-exception/39571423
try{
$this->mail->send();
return true;
}
catch (phpmailerException $e)
{
# log errors here
return $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e)
{
# log errors here
return $e->getMessage(); //Boring error messages from anything else!
}
}
}