Skip to content

Commit

Permalink
Merge pull request #19 from m1guelpf/plain-text-fix
Browse files Browse the repository at this point in the history
Ensure plain text emails don't throw exceptions
  • Loading branch information
mpociot authored Jun 18, 2020
2 parents dffa167 + 6537997 commit bd9ec9a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ public function send($view, array $data = [], $callback = null)
protected function applyDebugHeaders(Mailable $mailable)
{
$mailable->withSwiftMessage(function (\Swift_Message $swiftMessage) use ($mailable) {
$viewFile = $view = $viewContent = $viewData = null;

$viewFile = $this->getMailableViewFile($mailable);
$view = $this->getMailableView($viewFile);
$viewContent = $this->getMailableViewContent($view);

$viewData = $this->getMailableViewData($mailable);
if (! is_null($viewFile)) {
$view = $this->getMailableView($viewFile);
$viewContent = $this->getMailableViewContent($view);
$viewData = $this->getMailableViewData($mailable);
}


/**
* We need to base64 encode the data, as the SMTP header mime encoding could add unwanted
Expand Down
12 changes: 10 additions & 2 deletions src/TestMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

class TestMail extends Mailable
{
protected $plainText;

public function __construct($plainText = false)
{
$this->plainText = $plainText;
}

public function build()
{
return $this->subject("Test from HELO")
->markdown('helo::email');
$this->subject("Test from HELO");

return $this->plainText ? $this->text('helo::email') : $this->markdown('helo::email');
}
}
10 changes: 10 additions & 0 deletions tests/HeloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public function test_the_mail_commands_sends_the_mailable()
Mail::assertSent(TestMail::class);
}

/** @test */
public function test_plain_text_mails_work_correctly()
{
Mail::fake();

Mail::to('[email protected]')->send(new TestMail(true));

Mail::assertSent(TestMail::class);
}

/** @test */
public function test_the_correct_mailer_is_binded()
{
Expand Down

0 comments on commit bd9ec9a

Please sign in to comment.