Skip to content

Commit de6ca85

Browse files
committed
Support reply-to header
1 parent b7fca99 commit de6ca85

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/Messaging/Mail/MailBag.php

Lines changed: 43 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,22 @@ public function getFromName(): string
165179
return $this->from->getName();
166180
}
167181

182+
/**
183+
* @return string
184+
*/
185+
public function getReplyToEmail(): string
186+
{
187+
return $this->replyTo->getEmail();
188+
}
189+
190+
/**
191+
* @return string
192+
*/
193+
public function getReplyToName(): string
194+
{
195+
return $this->replyTo->getName();
196+
}
197+
168198
/**
169199
* @return string
170200
*/
@@ -253,6 +283,7 @@ private function getContent(ContentType $contentType): ?Content
253283

254284
return null;
255285
}
286+
256287
/**
257288
* @return array
258289
*/
@@ -302,6 +333,18 @@ function jsonSerialize(): array
302333
'recipients' => $recipients
303334
];
304335

336+
$replyTo = [];
337+
if ($this->getReplyToEmail()) {
338+
$replyTo['email'] = $this->getReplyToEmail();
339+
if ($this->getReplyToName()) {
340+
$replyTo['name'] = $this->getReplyToName();
341+
}
342+
}
343+
344+
if ($replyTo) {
345+
$data['replyTo'] = $replyTo;
346+
}
347+
305348
if ($contents) {
306349
$data['contents'] = $contents;
307350
}

0 commit comments

Comments
 (0)