8000 [Mailgun Mailer] fixed issue when using html body · symfony/symfony@4f766ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f766ba

Browse files
committed
[Mailgun Mailer] fixed issue when using html body
1 parent a25c2af commit 4f766ba

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Mailgun/Http/Api/MailgunTransport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function getPayload(Email $email, SmtpEnvelope $envelope): array
6868
{
6969
$headers = $email->getHeaders();
7070
$html = $email->getHtmlBody();
71-
if (null !== $html) {
71+
if (null !== $html && \is_resource($html)) {
7272
if (stream_get_meta_data($html)['seekable'] ?? false) {
7373
rewind($html);
7474
}

src/Symfony/Component/Mailer/Tests/TransportTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ public function testFromDsnMailgun()
168168
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
169169
$transport->send($message);
170170

171+
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html('test');
172+
$client = $this->createMock(HttpClientInterface::class);
173+
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
174+
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
175+
$transport->send($message);
176+
177+
$stream = fopen('data://text/plain,'.$message->getTextBody(), 'r');
178+
$message->html($stream);
179+
$client = $this->createMock(HttpClientInterface::class);
180+
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
181+
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
182+
$transport->send($message);
183+
171184
$this->expectException(LogicException::class);
172185
Transport::fromDsn('foo://mailgun');
173186
}

0 commit comments

Comments
 (0)
0