Skip to content

Commit 4fe6f38

Browse files
committed
bug #32131 [Mailgun Mailer] fixed issue when using html body (alOneh)
This PR was merged into the 4.3 branch. Discussion ---------- [Mailgun Mailer] fixed issue when using html body | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I tested the `symfony/mailgun-mailer` and get an issue when using the `api` scheme with a templated email cause we try to manipulate a stream whereas the `Symfony\Component\Mime\Email::getHtmlBody()` could return also a string (in my case it is one). The issue : ``` stream_get_meta_data() expects parameter 1 to be resource, string given ``` Commits ------- afbefe131b [Mailgun Mailer] fixed issue when using html body
2 parents 2eecd0b + b39f2ef commit 4fe6f38

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

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
}

Tests/TransportTest.php

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

178+
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html('test');
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+
184+
$stream = fopen('data://text/plain,'.$message->getTextBody(), 'r');
185+
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html($stream);
186+
$client = $this->createMock(HttpClientInterface::class);
187+
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
188+
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
189+
$transport->send($message);
190+
178191
$this->expectException(LogicException::class);
179192
Transport::fromDsn('foo://mailgun');
180193
}

TransportTest.php

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

178+
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html('test');
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+
184+
$stream = fopen('data://text/plain,'.$message->getTextBody(), 'r');
185+
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html($stream);
186+
$client = $this->createMock(HttpClientInterface::class);
187+
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
188+
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
189+
$transport->send($message);
190+
178191
$this->expectException(LogicException::class);
179192
Transport::fromDsn('foo://mailgun');
180193
}

0 commit comments

Comments
 (0)