From 9f21a977501e02df2ff8104fe970f84edf889218 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 17 Jun 2020 19:34:39 +0200 Subject: [PATCH 1/2] Ensure plain text emails don't throw exceptions --- src/Mailer.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Mailer.php b/src/Mailer.php index 5603824..da8cad6 100644 --- a/src/Mailer.php +++ b/src/Mailer.php @@ -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 From 65379974f8cbe14cfa9ab8a9d4bcc052e6da35cc Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Wed, 17 Jun 2020 19:43:22 +0200 Subject: [PATCH 2/2] Add a test to ensure plain text email works --- src/TestMail.php | 12 ++++++++++-- tests/HeloTest.php | 10 ++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/TestMail.php b/src/TestMail.php index a796cef..60dd488 100644 --- a/src/TestMail.php +++ b/src/TestMail.php @@ -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'); } } diff --git a/tests/HeloTest.php b/tests/HeloTest.php index 2b0d4a5..1813262 100644 --- a/tests/HeloTest.php +++ b/tests/HeloTest.php @@ -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('test@usehelo.com')->send(new TestMail(true)); + + Mail::assertSent(TestMail::class); + } + /** @test */ public function test_the_correct_mailer_is_binded() {