-
Notifications
You must be signed in to change notification settings - Fork 28
Allow sending only text/plain via Mailables #1058
Comments
You must have an error somewhere. This works fine to send text-only emails for me: public function build()
{
return $this->text('emails.text_message_content')
->replyTo($this->sender->email, $this->sender->name)
->subject($this->subject);
} And the view: @extends('emails.layout_textonly')
{!! $message_text !!} |
Strange. When I'm testing rendering a mailable inside a $mailable = new Mymailable();
$content = $mailable->render(); with a mailable with no I need to dig a bit deeper and see if this really is some user error on my end or if this needs a real fix. |
OK going to paste my current setup (with dummy content) for brevity: MyMailablepublic function setSomeValue($string)
{
$this->some_value = $string;
}
public function build()
{
$some_value = (string) $this->some_value;
return $this->subject('Hello World')
->text('mail.hello-world')
->with('value', $some_value);
} resources/views/mail/hello-world.blade.php
MyMailableTest$m = new MyMailable();
$m->setSomeValue('foobar');
$m_content = $m->render();
$this->assertContains('foobar', $m_content); With this setup when I run
I receive
But when I alter public function build()
{
$some_value = (string) $this->some_value;
return $this->subject('Hello World')
->view('mail.hello-world')
->text('mail.hello-world')
->with('value', $some_value);
} Then everything works as expected and the assertion succeeds in my test case. |
@rask You're not going crazy! The public function render($view, array $data = [])
{
// First we need to parse the view, which could either be a string or an array
// containing both an HTML and plain text versions of the view which should
// be used when sending an e-mail. We will extract both of them out here.
list($view, $plain, $raw) = $this->parseView($view);
$data['message'] = $this->createMessage();
return $this->renderView($view, $data);
} In your case, Adding in this simple fallback would get your test passing: list($view, $plain, $raw) = $this->parseView($view);
$view = $view ?: $plain; I'll submit a PR fix for this momentarily. Appreciate the report! 👍 |
Neat, thanks and no problem! I'll be following update notes. :) |
@rask Someone was finally able to submit a PR and this should be fixed in Laravel 5.6.18+. |
@AkenRoberts Alrighty, good to hear! |
Thanks @AkenRoberts!
When will 5.6.18 be available via composer? |
@mbaierl Laravel 5.6.21 should be the current recent version available on Packagist.
If |
Thanks @AkenRoberts - learned something new :-) |
Looks like this can be closed now |
I guess so. Thanks everyone! |
From what I understand Mailables require a HTML view in order to work. If you define only a text view as such
Then the mailable fails with an error saying
invalid view []
or similar. After adding a->view('view.name')
tobuild()
the Mailable works OK.Or is this intended and I'm asking for trouble here? Why can't I just send a text/plain email with a Mailable? I would prefer to have light emails for a light application and setting up HTML emails is a chore and maintaining those is tedious.
The text was updated successfully, but these errors were encountered: