Skip to content

Commit bd9ec9a

Browse files
authored
Merge pull request #19 from m1guelpf/plain-text-fix
Ensure plain text emails don't throw exceptions
2 parents dffa167 + 6537997 commit bd9ec9a

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/Mailer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,16 @@ public function send($view, array $data = [], $callback = null)
2727
protected function applyDebugHeaders(Mailable $mailable)
2828
{
2929
$mailable->withSwiftMessage(function (\Swift_Message $swiftMessage) use ($mailable) {
30+
$viewFile = $view = $viewContent = $viewData = null;
31+
3032
$viewFile = $this->getMailableViewFile($mailable);
31-
$view = $this->getMailableView($viewFile);
32-
$viewContent = $this->getMailableViewContent($view);
3333

34-
$viewData = $this->getMailableViewData($mailable);
34+
if (! is_null($viewFile)) {
35+
$view = $this->getMailableView($viewFile);
36+
$viewContent = $this->getMailableViewContent($view);
37+
$viewData = $this->getMailableViewData($mailable);
38+
}
39+
3540

3641
/**
3742
* We need to base64 encode the data, as the SMTP header mime encoding could add unwanted

src/TestMail.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66

77
class TestMail extends Mailable
88
{
9+
protected $plainText;
10+
11+
public function __construct($plainText = false)
12+
{
13+
$this->plainText = $plainText;
14+
}
15+
916
public function build()
1017
{
11-
return $this->subject("Test from HELO")
12-
->markdown('helo::email');
18+
$this->subject("Test from HELO");
19+
20+
return $this->plainText ? $this->text('helo::email') : $this->markdown('helo::email');
1321
}
1422
}

tests/HeloTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ public function test_the_mail_commands_sends_the_mailable()
2929
Mail::assertSent(TestMail::class);
3030
}
3131

32+
/** @test */
33+
public function test_plain_text_mails_work_correctly()
34+
{
35+
Mail::fake();
36+
37+
Mail::to('[email protected]')->send(new TestMail(true));
38+
39+
Mail::assertSent(TestMail::class);
40+
}
41+
3242
/** @test */
3343
public function test_the_correct_mailer_is_binded()
3444
{

0 commit comments

Comments
 (0)