|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* @license MIT |
|
4
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the EmmetBlue project, please read the license document |
|
7
|
|
|
* available in the root level of the project |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace EmmetBlue\Core\Factory; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class MailerFactory. |
|
13
|
|
|
* |
|
14
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
15
|
|
|
* |
|
16
|
|
|
* @since v0.0.1 13/02/2017 13:06 |
|
17
|
|
|
*/ |
|
18
|
|
|
class MailerFactory |
|
19
|
|
|
{ |
|
20
|
|
|
private $mail; |
|
21
|
|
|
public function __construct(array $sender, array $recipients, array $message){ |
|
22
|
|
|
$smtpConfigJson = file_get_contents("bin/configs/smtp-config.json"); |
|
23
|
|
|
|
|
24
|
|
|
$smtpConfig = json_decode($smtpConfigJson); |
|
25
|
|
|
|
|
26
|
|
|
$mail = new \PHPMailer; |
|
27
|
|
|
$mail->SMTPDebug = $smtpConfig->debug; |
|
28
|
|
|
$mail->isSMTP(); |
|
29
|
|
|
$mail->Host = $smtpConfig->host; |
|
30
|
|
|
$mail->SMTPAuth = $smtpConfig->auth; |
|
31
|
|
|
$mail->Username = $smtpConfig->user; |
|
32
|
|
|
$mail->Password = $smtpConfig->password; |
|
33
|
|
|
$mail->SMTPSecure = $smtpConfig->secure; |
|
34
|
|
|
$mail->Port = $smtpConfig->port; |
|
35
|
|
|
|
|
36
|
|
|
$mail->From = $sender["address"]; |
|
37
|
|
|
$mail->FromName = $sender["name"]; |
|
38
|
|
|
$mail->addReplyTo = $sender["replyTo"]; |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
foreach ($recipients as $key => $value) { |
|
41
|
|
|
$mail->addAddress($value["address"]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$mail->Subject = $message["subject"]; |
|
45
|
|
|
$mail->Body = $message["body"]; |
|
46
|
|
|
$mail->AltBody = $message["alt"]; |
|
47
|
|
|
$mail->isHTML($message["isHtml"]); |
|
48
|
|
|
|
|
49
|
|
|
$this->mail = $mail; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function send(){ |
|
53
|
|
|
if (!$this->mail->send()){ |
|
54
|
|
|
return $this->mail->ErrorInfo; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return ["result"=>true]; |
|
58
|
|
|
} |
|
59
|
|
|
} |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.