Skip to content

Commit be507c7

Browse files
authored
Add reply to support (#1)
* add replyTo support to SendGridMessage * set replyTo on Mail
1 parent 34606bc commit be507c7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/SendGridMessage.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use SendGrid\Mail\From;
66
use SendGrid\Mail\Mail;
7+
use SendGrid\Mail\ReplyTo;
78
use SendGrid\Mail\To;
89

910
class SendGridMessage
@@ -22,6 +23,11 @@ class SendGridMessage
2223
*/
2324
public $tos = [];
2425

26+
/**
27+
* The reply to address for the message.
28+
*/
29+
public $replyTo;
30+
2531
/**
2632
* The SendGrid Template ID for the message.
2733
*
@@ -76,6 +82,13 @@ public function to($email, $name = null, $data = [])
7682
return $this;
7783
}
7884

85+
public function replyTo($email, $name = null)
86+
{
87+
$this->replyTo = new ReplyTo($email, $name);
88+
89+
return $this;
90+
}
91+
7992
public function payload($payload)
8093
{
8194
$this->payload = $payload;
@@ -93,6 +106,8 @@ public function build(): Mail
93106
$this->tos
94107
);
95108

109+
$email->setReplyTo($this->replyTo);
110+
96111
$email->setTemplateId($this->templateId);
97112

98113
foreach ($this->payload as $key => $value) {

tests/SendGridChannelTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function testEmailIsSentViaSendGrid()
3939
$this->assertEquals($message->tos[0]->getName(), 'Example User1');
4040
$this->assertEquals($message->payload['bar'], 'foo');
4141
$this->assertEquals($message->payload['baz'], 'foo2');
42-
42+
$this->assertEquals($message->replyTo->getEmail(), 'replyto@example.com');
43+
$this->assertEquals($message->replyTo->getName(), 'Reply To');
4344
// TODO: Verify that the Mail instance passed contains all the info from above
4445
$sendgrid->shouldReceive('send')->once()->andReturn($response);
4546

@@ -59,6 +60,7 @@ public function toSendGrid($notifiable)
5960
return (new SendGridMessage('sendgrid-template-id'))
6061
->from('test@example.com', 'Example User')
6162
->to('test+test1@example.com', 'Example User1')
63+
->replyTo('replyto@example.com', 'Reply To')
6264
->payload([
6365
'bar' => 'foo',
6466
'baz' => 'foo2',

0 commit comments

Comments
 (0)