Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/SendGridMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use SendGrid\Mail\From;
use SendGrid\Mail\Mail;
use SendGrid\Mail\ReplyTo;
use SendGrid\Mail\To;

class SendGridMessage
Expand All @@ -22,6 +23,11 @@ class SendGridMessage
*/
public $tos = [];

/**
* The reply to address for the message.
*/
public $replyTo;

/**
* The SendGrid Template ID for the message.
*
Expand Down Expand Up @@ -76,6 +82,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;
Expand All @@ -93,6 +106,8 @@ public function build(): Mail
$this->tos
);

$email->setReplyTo($this->replyTo);

$email->setTemplateId($this->templateId);

foreach ($this->payload as $key => $value) {
Expand Down
4 changes: 3 additions & 1 deletion tests/SendGridChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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',
Expand Down