Skip to content

Commit 96a6c30

Browse files
Nyholmnicolas-grekas
authored andcommitted
[Mailer] Make sure you can pass custom headers to Mailgun
1 parent f4cbca9 commit 96a6c30

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Tests/Transport/SendgridApiTransportTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridApiTransport;
16+
use Symfony\Component\Mailer\Envelope;
1617
use Symfony\Component\Mime\Address;
1718
use Symfony\Component\Mime\Email;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -149,4 +150,20 @@ public function testLineBreaksInEncodedAttachment()
149150

150151
$mailer->send($email);
151152
}
153+
154+
public function testCustomHeader()
155+
{
156+
$email = new Email();
157+
$email->getHeaders()->addTextHeader('foo', 'bar');
158+
$envelope = new Envelope(new Address('[email protected]'), [new Address('[email protected]')]);
159+
160+
$transport = new SendgridApiTransport('ACCESS_KEY');
161+
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
162+
$method->setAccessible(true);
163+
$payload = $method->invoke($transport, $email, $envelope);
164+
165+
$this->assertArrayHasKey('headers', $payload);
166+
$this->assertArrayHasKey('foo', $payload['headers']);
167+
$this->assertEquals('bar', $payload['headers']['foo']);
168+
}
152169
}

Transport/SendgridApiTransport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function getPayload(Email $email, Envelope $envelope): array
104104
continue;
105105
}
106106

107-
$payload['headers'][$name] = $header->toString();
107+
$payload['headers'][$name] = $header->getBodyAsString();
108108
}
109109

110110
return $payload;

0 commit comments

Comments
 (0)