Skip to content

[Mailer] Fix reply-to functionality in the SendgridApiTransport #37527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,30 @@ public function testCustomHeader()
$this->assertArrayHasKey('foo', $payload['headers']);
$this->assertEquals('bar', $payload['headers']['foo']);
}

public function testReplyTo()
{
$from = 'from@example.com';
$to = 'to@example.com';
$replyTo = 'replyto@example.com';
$email = new Email();
$email->from($from)
->to($to)
->replyTo($replyTo)
->text('content');
$envelope = new Envelope(new Address($from), [new Address($to)]);

$transport = new SendgridApiTransport('ACCESS_KEY');
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
$method->setAccessible(true);
$payload = $method->invoke($transport, $email, $envelope);

$this->assertArrayHasKey('from', $payload);
$this->assertArrayHasKey('email', $payload['from']);
$this->assertSame($from, $payload['from']['email']);

$this->assertArrayHasKey('reply_to', $payload);
$this->assertArrayHasKey('email', $payload['reply_to']);
$this->assertSame($replyTo, $payload['reply_to']['email']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ private function getPayload(Email $email, Envelope $envelope): array
if ($emails = array_map($addressStringifier, $email->getBcc())) {
$personalization['bcc'] = $emails;
}
if ($emails = array_map($addressStringifier, $email->getReplyTo())) {
// Email class supports an array of reply-to addresses,
// but SendGrid only supports a single address
$payload['reply_to'] = $emails[0];
}

$payload['personalizations'][] = $personalization;

// these headers can't be overwritten according to Sendgrid docs
// see https://developers.pepipost.com/migration-api/new-subpage/email-send
// see https://sendgrid.api-docs.io/v3.0/mail-send/mail-send-errors#-Headers-Errors
$headersToBypass = ['x-sg-id', 'x-sg-eid', 'received', 'dkim-signature', 'content-transfer-encoding', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to'];
foreach ($email->getHeaders()->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy