From 8e4addd13cecfb208edd35bf4930f760bcb39197 Mon Sep 17 00:00:00 2001 From: Semih Cosu Date: Tue, 3 Aug 2021 14:51:42 +0300 Subject: [PATCH 1/2] add replyTo support to SendGridMessage --- src/SendGridMessage.php | 10 ++++++++++ tests/SendGridChannelTest.php | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/SendGridMessage.php b/src/SendGridMessage.php index fac26cb..4379a6f 100644 --- a/src/SendGridMessage.php +++ b/src/SendGridMessage.php @@ -4,6 +4,7 @@ use SendGrid\Mail\From; use SendGrid\Mail\Mail; +use SendGrid\Mail\ReplyTo; use SendGrid\Mail\To; class SendGridMessage @@ -22,6 +23,8 @@ class SendGridMessage */ public $tos = []; + + /** * The SendGrid Template ID for the message. * @@ -76,6 +79,13 @@ public function to($email, $name = null, $data = []) return $this; } + public function replyTo($email, $name = null) + { + $this->replyTo = new ReplyTo($email, $name); + + return $this; + } + public function payload($payload) { $this->payload = $payload; diff --git a/tests/SendGridChannelTest.php b/tests/SendGridChannelTest.php index 36c914a..e38fb53 100644 --- a/tests/SendGridChannelTest.php +++ b/tests/SendGridChannelTest.php @@ -39,7 +39,8 @@ public function testEmailIsSentViaSendGrid() $this->assertEquals($message->tos[0]->getName(), 'Example User1'); $this->assertEquals($message->payload['bar'], 'foo'); $this->assertEquals($message->payload['baz'], 'foo2'); - + $this->assertEquals($message->replyTo->getEmail(), 'replyto@example.com'); + $this->assertEquals($message->replyTo->getName(), 'Reply To'); // TODO: Verify that the Mail instance passed contains all the info from above $sendgrid->shouldReceive('send')->once()->andReturn($response); @@ -59,6 +60,7 @@ public function toSendGrid($notifiable) return (new SendGridMessage('sendgrid-template-id')) ->from('test@example.com', 'Example User') ->to('test+test1@example.com', 'Example User1') + ->replyTo('replyto@example.com', 'Reply To') ->payload([ 'bar' => 'foo', 'baz' => 'foo2', From 16081564a407b28d51a8a5fd86cdeebf2d704eda Mon Sep 17 00:00:00 2001 From: Semih Cosu Date: Tue, 3 Aug 2021 15:05:16 +0300 Subject: [PATCH 2/2] set replyTo on Mail --- src/SendGridMessage.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/SendGridMessage.php b/src/SendGridMessage.php index 4379a6f..86f695c 100644 --- a/src/SendGridMessage.php +++ b/src/SendGridMessage.php @@ -23,7 +23,10 @@ class SendGridMessage */ public $tos = []; - + /** + * The reply to address for the message. + */ + public $replyTo; /** * The SendGrid Template ID for the message. @@ -82,7 +85,7 @@ public function to($email, $name = null, $data = []) public function replyTo($email, $name = null) { $this->replyTo = new ReplyTo($email, $name); - + return $this; } @@ -103,6 +106,8 @@ public function build(): Mail $this->tos ); + $email->setReplyTo($this->replyTo); + $email->setTemplateId($this->templateId); foreach ($this->payload as $key => $value) {