Skip to content

Commit 0bb40aa

Browse files
authored
Merge pull request #9 from caltha-eu/reply-to
Support reply-to header
2 parents b7fca99 + 107b5de commit 0bb40aa

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/Messaging/Mail/MailBag.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ class MailBag implements \JsonSerializable
1717
*/
1818
private $from;
1919

20+
/**
21+
* @var From Reply-To
22+
*/
23+
private $replyTo;
24+
2025
/**
2126
* @var string
2227
*/
@@ -63,6 +68,15 @@ public function setFrom(string $fromEmail, string $fromName): void
6368
$this->from = new From(new Email($fromEmail), $fromName);
6469
}
6570

71+
/**
72+
* @param string $replyToEmail
73+
* @param string $replyToName
74+
*/
75+
public function setReplyTo(string $replyToEmail, string $replyToName): void
76+
{
77+
$this->replyTo = new From(new Email($replyToEmail), $replyToName);
78+
}
79+
6680
/**
6781
* @param mixed $subject
6882
*/
@@ -165,6 +179,30 @@ public function getFromName(): string
165179
return $this->from->getName();
166180
}
167181

182+
/**
183+
* @return string
184+
*/
185+
public function getReplyToEmail(): ?string
186+
{
187+
if ($this->replyTo) {
188+
return $this->replyTo->getEmail();
189+
}
190+
191+
return null;
192+
}
193+
194+
/**
195+
* @return string
196+
*/
197+
public function getReplyToName(): ?string
198+
{
199+
if ($this->replyTo) {
200+
return $this->replyTo->getName();
201+
}
202+
203+
return null;
204+
}
205+
168206
/**
169207
* @return string
170208
*/
@@ -253,6 +291,7 @@ private function getContent(ContentType $contentType): ?Content
253291

254292
return null;
255293
}
294+
256295
/**
257296
* @return array
258297
*/
@@ -302,6 +341,18 @@ function jsonSerialize(): array
302341
'recipients' => $recipients
303342
];
304343

344+
$replyTo = [];
345+
if ($this->getReplyToEmail()) {
346+
$replyTo['email'] = $this->getReplyToEmail();
347+
if ($this->getReplyToName()) {
348+
$replyTo['name'] = $this->getReplyToName();
349+
}
350+
}
351+
352+
if ($replyTo) {
353+
$data['replyTo'] = $replyTo;
354+
}
355+
305356
if ($contents) {
306357
$data['contents'] = $contents;
307358
}

0 commit comments

Comments
 (0)