-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathEmail.php
More file actions
129 lines (112 loc) · 3.45 KB
/
Email.php
File metadata and controls
129 lines (112 loc) · 3.45 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
121
122
123
124
125
126
127
128
129
<?php
namespace Utopia\Messaging\Messages;
use Utopia\Messaging\Message;
use Utopia\Messaging\Messages\Email\Attachment;
class Email implements Message
{
/**
* @param array<string> $to The recipients of the email.
* @param string $subject The subject of the email.
* @param string $content The content of the email.
* @param string $fromName The name of the sender.
* @param string $fromEmail The email address of the sender.
* @param array<array<string,string>>|null $cc . The CC recipients of the email. Each recipient should be an array containing a "name" and an "email" key.
* @param array<array<string,string>>|null $bcc . The BCC recipients of the email. Each recipient should be an array containing a "name" and an "email" key.
* @param string|null $replyToName The name of the reply to.
* @param string|null $replyToEmail The email address of the reply to.
* @param array<Attachment>|null $attachments The attachments of the email.
* @param bool $html Whether the message is HTML or not.
*
* @throws \InvalidArgumentException
*/
public function __construct(
private array $to,
private string $subject,
private string $content,
private string $fromName,
private string $fromEmail,
private ?string $replyToName = null,
private ?string $replyToEmail = null,
private ?array $cc = null,
private ?array $bcc = null,
private ?array $attachments = null,
private bool $html = false,
) {
if (\is_null($this->replyToName)) {
$this->replyToName = $this->fromName;
}
if (\is_null($this->replyToEmail)) {
$this->replyToEmail = $this->fromEmail;
}
if (!\is_null($this->cc)) {
foreach ($this->cc as $recipient) {
if (!isset($recipient['email'])) {
throw new \InvalidArgumentException('Each CC recipient must have at least an email');
}
}
}
if (!\is_null($this->bcc)) {
foreach ($this->bcc as $recipient) {
if (!isset($recipient['email'])) {
throw new \InvalidArgumentException('Each BCC recipient must have at least an email');
}
}
}
}
/**
* @return array<string>
*/
public function getTo(): array
{
return $this->to;
}
public function getSubject(): string
{
return $this->subject;
}
public function getContent(): string
{
return $this->content;
}
public function getFromName(): string
{
return $this->fromName;
}
public function getFromEmail(): string
{
return $this->fromEmail;
}
public function getReplyToName(): string
{
return $this->replyToName;
}
public function getReplyToEmail(): string
{
return $this->replyToEmail;
}
/**
* @return array<array<string, string>>|null
*/
public function getCC(): ?array
{
return $this->cc;
}
/**
* @return array<array<string, string>>|null
*/
public function getBCC(): ?array
{
return $this->bcc;
}
/**
* @return array<string, mixed>|null
*/
public function getAttachments(): ?array
{
return $this->attachments;
}
public function isHtml(): bool
{
return $this->html;
}
}