-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmail.php
More file actions
62 lines (51 loc) · 1.49 KB
/
mail.php
File metadata and controls
62 lines (51 loc) · 1.49 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
<?php
namespace Plugins\mail;
use \Typemill\Plugin;
use \PHPMailer\PHPMailer\PHPMailer;
use \PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
class Mail extends Plugin
{
public static function getSubscribedEvents()
{
return [
'onTwigLoaded' => ['onTwigLoaded', 0]
];
}
# add the mail configuration
public function onTwigLoaded()
{
$mail = new PHPMailer;
$config = $this->getPluginSettings();
$twig = $this->getTwig();
$container = $this->container;
$this->container->set('mail', function($container) use ($mail, $config, $twig)
{
$mail->From = $config['from_address'];
$mail->FromName = $config['from_name'];
$mail->Sender = $config['from_address'];
if(isset($config['CharSet']))
{
$mail->CharSet = $config['CharSet'];
}
if(isset($config['SMTP']) && $config['SMTP'])
{
date_default_timezone_set('Etc/UTC');
$mail->isSMTP();
$mail->Host = $config['host'];
$mail->Port = $config['port'];
$mail->SMTPDebug = 0;
# optional
if(isset($config['SMTPSecure'])){ $mail->SMTPSecure = $config['SMTPSecure']; }
if(isset($config['SMTPAuth'])){ $mail->SMTPAuth = $config['SMTPAuth']; }
if(isset($config['username'])){ $mail->Username = $config['username']; }
if(isset($config['password'])){ $mail->Password = $config['password']; }
}
else
{
$mail->isMail();
}
return new MailHandler($mail, $twig);
});
}
}