|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* File: TransactionalEmailHandler.php |
|
4
|
|
|
* |
|
5
|
|
|
* @author Maciej Sławik <[email protected]> |
|
6
|
|
|
* Github: https://github.com/maciejslawik |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MSlwk\FreshMail\Handler\Message; |
|
10
|
|
|
|
|
11
|
|
|
use MSlwk\FreshMail\Handler\AbstractHandler; |
|
12
|
|
|
|
|
13
|
|
|
class TransactionalEmailHandler extends AbstractHandler |
|
14
|
|
|
{ |
|
15
|
|
|
const API_ENDPOINT = '/rest/mail'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param string $email |
|
19
|
|
|
* @param string $subject |
|
20
|
|
|
* @param string $content |
|
21
|
|
|
* @param string $fromEmail |
|
22
|
|
|
* @param string $fromName |
|
23
|
|
|
* @param string $replyTo |
|
24
|
|
|
* @param string $encoding |
|
25
|
|
|
* @param string $attachmentUrl |
|
26
|
|
|
* @param string $tag |
|
27
|
|
|
* @param bool $tracking |
|
28
|
|
|
* @param string $domain |
|
29
|
|
|
* @return null |
|
30
|
|
|
*/ |
|
31
|
112 |
|
public function sendTransactionalEmail( |
|
32
|
|
|
string $email, |
|
33
|
|
|
string $subject, |
|
34
|
|
|
string $content, |
|
35
|
|
|
string $fromEmail = '', |
|
36
|
|
|
string $fromName = '', |
|
37
|
|
|
string $replyTo = '', |
|
38
|
|
|
string $encoding = 'UTF-8', |
|
39
|
|
|
string $attachmentUrl = '', |
|
40
|
|
|
string $tag = '', |
|
41
|
|
|
bool $tracking = false, |
|
42
|
|
|
string $domain = '' |
|
43
|
|
|
) { |
|
44
|
112 |
|
$getParameters = []; |
|
45
|
32 |
|
$postParameters = [ |
|
46
|
112 |
|
'subscriber' => $email, |
|
47
|
112 |
|
'subject' => $subject, |
|
48
|
112 |
|
'html' => $content, |
|
49
|
|
|
'from' => $fromEmail ?: null, |
|
50
|
|
|
'from_name' => $fromName ?: null, |
|
51
|
|
|
'reply_to' => $replyTo ?: null, |
|
52
|
|
|
'encoding' => $encoding ?: null, |
|
53
|
|
|
'attachments' => $attachmentUrl ?: null, |
|
54
|
|
|
'tracking' => $tracking ?: null, |
|
55
|
|
|
'domain' => $domain ?: null, |
|
56
|
|
|
'tag' => $tag ?: null |
|
57
|
|
|
]; |
|
58
|
|
|
|
|
59
|
80 |
|
$postParameters = array_filter($postParameters, function ($value) { |
|
60
|
112 |
|
return $value !== null; |
|
61
|
112 |
|
}); |
|
62
|
112 |
|
$this->processRequest($getParameters, $postParameters); |
|
63
|
7 |
|
return null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
7 |
|
protected function getApiEndpoint(): string |
|
70
|
|
|
{ |
|
71
|
7 |
|
return self::API_ENDPOINT; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|