0

I'm using october's mail fascade to send emails. In the docs is written:

By default, the view given to the send method is assumed to contain HTML. However, by passing an array as the first argument to the send method, you may specify a plain text view to send in addition to the HTML view:

Mail::send(['acme.blog::mail.html', 'acme.blog::mail.text'], $data, $callback);

But when I do so, the mail.text view file is ignored. For the plain text part of the message also the mail.html view file is used, containing <br /> before linebreak.

Did I miss something? Or is this a bug?

My code:

$vars = ['msg' => 'Hello world'];

Mail::send(
    ['text' => 'respective.test::mails.text', 
     'html' => 'respective.test::mails.html'],  
    $vars, function($message) { 
        $message->to('name@example.com'); 
        $message->subject('Test message');
    });

I tried it with and without array keys. The first view file is always used for both parts. I think, this is a bug.

schmauch
  • 630
  • 1
  • 7
  • 10

2 Answers2

0

On https://octobercms.com/forum/post/mail-with-plain-text-alternative mjauvin gave an answer that worked for me:

I don't know but you can have both views (plain text and html) in the same view file.

schmauch
  • 630
  • 1
  • 7
  • 10
0

I believe the order of items in the array matters. The docs say:

By default, the view given to the send method is assumed to contain HTML. However, by passing an array as the first argument to the send method, you may specify a plain text view to send in addition to the HTML view: Mail::send(['acme.blog::mail.html', 'acme.blog::mail.text'], $data, $callback);

The wording suggests that the first item in the array would be html and the second would be text. Even though it isn't explicit.


Just in case anyone is confused by the OP's answer. The mail template file can hold header, text, html, in the one file separated by the ==.

subject = "Your product has been added to OctoberCMS project"
==

Hi {{ name }},

Good news! User {{ user }} just added your product "{{ product }}" to a project.

This message was sent using no formatting (plain text)
==

<p>Hi {{ name }},</p>

<p>Good news! User {{ user }} just added your product <strong>{{ product }}</strong> to a project.</p>

<p>This email was sent using formatting (HTML)</p>
Pettis Brandon
  • 875
  • 1
  • 6
  • 8