[Mailgun Mailer] fixed issue when using html body

This commit is contained in:
Hippolyte Alain 2019-06-21 13:43:07 +02:00
parent a25c2af559
commit afbefe131b
2 changed files with 14 additions and 1 deletions

View File

@ -68,7 +68,7 @@ class MailgunTransport extends AbstractApiTransport
{
$headers = $email->getHeaders();
$html = $email->getHtmlBody();
if (null !== $html) {
if (null !== $html && \is_resource($html)) {
if (stream_get_meta_data($html)['seekable'] ?? false) {
rewind($html);
}

View File

@ -168,6 +168,19 @@ class TransportTest extends TestCase
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
$transport->send($message);
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html('test');
$client = $this->createMock(HttpClientInterface::class);
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
$transport->send($message);
$stream = fopen('data://text/plain,'.$message->getTextBody(), 'r');
$message = (new Email())->from('me@me.com')->to('you@you.com')->subject('hello')->html($stream);
$client = $this->createMock(HttpClientInterface::class);
$client->expects($this->once())->method('request')->with('POST', 'https://api.mailgun.net/v3/pa%24s/messages')->willReturn($response);
$transport = Transport::fromDsn('api://'.urlencode('u$er').':'.urlencode('pa$s').'@mailgun?region=us', $dispatcher, $client, $logger);
$transport->send($message);
$this->expectException(LogicException::class);
Transport::fromDsn('foo://mailgun');
}