1 | <?php |
||
9 | class Mailer extends SilverstripeMailer |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | * @config |
||
14 | */ |
||
15 | private static $api_domain = ''; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | * @config |
||
20 | */ |
||
21 | private static $api_endpoint = 'api.mailgun.net'; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | * @config |
||
26 | */ |
||
27 | private static $api_key = ''; |
||
28 | |||
29 | /** |
||
30 | * @var boolean |
||
31 | * @config |
||
32 | */ |
||
33 | private static $api_ssl = true; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | * @config |
||
38 | */ |
||
39 | private static $api_version = 'v3'; |
||
40 | |||
41 | /** |
||
42 | * An array of temporary file handles opened to store attachments |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $tempFileHandles = []; |
||
46 | |||
47 | /** |
||
48 | * @var Mailgun |
||
49 | */ |
||
50 | protected $mailgunClient; |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 12 | public function __construct() |
|
65 | |||
66 | /** |
||
67 | * @param Mailgun $client |
||
68 | * @return self |
||
69 | */ |
||
70 | 12 | public function setMailgunClient(Mailgun $client) |
|
75 | |||
76 | /** |
||
77 | * @return Mailgun |
||
78 | */ |
||
79 | 1 | public function getMailgunClient() |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 1 | public function sendPlain($to, $from, $subject, $plainContent, $attachments = [], $headers = []) |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 1 | public function sendHTML($to, $from, $subject, $htmlContent, $attachments = [], $headers = [], $plainContent = '') |
|
99 | |||
100 | /** |
||
101 | * @param string $to |
||
102 | * @param string $from |
||
103 | * @param string $subject |
||
104 | * @param string $content |
||
105 | * @param string $plainContent |
||
106 | * @param array $attachments |
||
107 | * @param array $headers |
||
108 | */ |
||
109 | 3 | protected function sendMessage($to, $from, $subject, $content, $plainContent, $attachments, $headers) |
|
138 | |||
139 | /** |
||
140 | * @param MessageBuilder $builder |
||
141 | * @param string $to |
||
142 | * @param string $from |
||
143 | * @param string $subject |
||
144 | * @param string $content |
||
145 | * @param string $plainContent |
||
146 | * @param array $attachments |
||
147 | * @param array $headers |
||
148 | */ |
||
149 | 2 | protected function buildMessage( |
|
204 | |||
205 | /** |
||
206 | * @todo This can't deal with mismatched quotes, or commas in names. |
||
207 | * E.g. "Smith, John" <[email protected]> or "John O'smith" <[email protected]> |
||
208 | * @param string |
||
209 | * @return array |
||
210 | */ |
||
211 | 3 | protected function parseAddresses($addresses) |
|
230 | |||
231 | /** |
||
232 | * Prepare attachments for sending. SilverStripe extracts the content and |
||
233 | * passes that to the mailer, so to save encoding it we just write them all |
||
234 | * to individual files and let Mailgun deal with the rest. |
||
235 | * |
||
236 | * @todo Can we handle this better? |
||
237 | * @param array $attachments |
||
238 | * @return array |
||
239 | */ |
||
240 | 2 | protected function prepareAttachments(array $attachments) |
|
255 | |||
256 | /** |
||
257 | * @param string $contents |
||
258 | * @return string |
||
259 | */ |
||
260 | 2 | protected function writeToTempFile($contents) |
|
273 | |||
274 | /** |
||
275 | * @return void |
||
276 | */ |
||
277 | 1 | protected function closeTempFileHandles() |
|
285 | } |
||
286 |