abkrim's avatar
Level 13

Notification with markdown not work

I've a custom command that generate a report and at end, send a Mail to admin.

        $lines = $r->markdown;

        Mail::to(['[email protected]'])->send(new VersionSchemaReport($lines));
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class VersionSchemaReport extends Mailable
{
    use Queueable, SerializesModels;

    public $lines;


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

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('mail.dbschema.report');
    }
}

blade

@component('mail::message')
# Report DBSchema change for iRedMail Databases

@foreach ( $lines as $line )
    {{ $line }}
@endforeach


Thanks,<br>
{{ config('app.name') }}
@endcomponent

Content of lines is array

 0 => "## vmail"
  1 => "### admin"
  2 => "| Type | Name | Key | Old | New |"
  3 => "| ---- | ---- | --- | --- | --- |"
  4 => "| Indexes |"
  5 => "| Modification  | admin_active_index | name | admin_active_index | admin_username_unique |"
  6 => "| Modification  | admin_active_index | unique |  | Unique |"
  7 => "| Modification  | admin_active_index | columns | active | username |"
  8 => "| Modification  | admin_passwordlastchange_index | name | admin_passwordlastchange_index | admin_expired_index |"
  9 => "| Modification  | admin_passwordlastchange_index | columns | passwordlastchange | expired |"
  10 => "| Modification  | admin_expired_index | name | admin_expired_index | admin_passwordlastchange_index |"
  11 => "| Modification  | admin_expired_index | columns | expired | passwordlastchange |"
  12 => "| Modification  | admin_username_unique | name | admin_username_unique | admin_active_index |"
  13 => "| Modification  | admin_username_unique | unique | Unique |  |"
  14 => "| Modification  | admin_username_unique | columns | username | active |"
  15 => "### alias"
  16 => "| Type | Name | Key | Old | New |"
  17 => "| ---- | ---- | --- | --- | --- |"
  18 => "| Indexes |"
  19 => "| Modification  | active | name | active | PRIMARY |"
  20 => "| Modification  | active | unique |  | Unique |"
  21 => "| Modification  | active | columns | active | address |"
  22 => "| Modification  | domain | name | domain | expired |"
  23 => "| Modification  | domain | columns | domain | expired |"
  24 => "| Modification  | expired | name | expired | domain |"
  25 => "| Modification  | expired | columns | expired | domain |"
  26 => "| Modification  | PRIMARY | name | PRIMARY | active |"
  27 => "| Modification  | PRIMARY | unique | Unique |  |"
  28 => "| Modification  | PRIMARY | columns | address | active |"
  29 => "### alias_domain"
  30 => "| Type | Name | Key | Old | New |"
  31 => "| ---- | ---- | --- | --- | --- |"
  32 => "| Indexes |"
  33 => "| Modification  | target_domain | name | target_domain | PRIMARY |"
  34 => "| Modification  | target_domain | unique |  | Unique |"
  35 => "| Modification  | target_domain | columns | target_domain | alias_domain |"
  36 => "| Modification  | PRIMARY | name | PRIMARY | target_domain |"
  37 => "| Modification  | PRIMARY | unique | Unique |  |"
  38 => "| Modification  | PRIMARY | columns | alias_domain | target_domain |"
...

When read message get a error. Only first line of message before @foreach is formated in markdown.

After @foreach every is enclosed into <pre> tag

 <h1 style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box; color: #3d4852; font-size: 19px; font-weight: bold; margin-top: 0; text-align: left;">Report DBSchema change for iRedMail Databases</h1>
<pre style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; box-sizing: border-box;"><code>## vmail
### admin
| Type | Name | Key | Old | New |
| ---- | ---- | --- | --- | --- |
| Indexes |
| Modification  | admin_active_index | name | admin_active_index | admin_username_unique |

https://imgur.com/i8JwMSd

0 likes
4 replies
Snapey's avatar

Can you please format your code by putting 3 backticks ``` on a line before and after each code block where you are describing what you get?

My thoughts are that you need blank line before the table.

Snapey's avatar
Snapey
Best Answer
Level 122

or...

remove the indent, it will put spaces before your markdown

    {{ $line }}
abkrim's avatar
Level 13

Thanks.

This work fine.

With any indent.

@component('mail::message')
# Report DBSchema change for iRedMail Databases

@foreach ( $lines as $line )
{{ $line }}
@endforeach


Thanks,<br>
{{ config('app.name') }}
@endcomponent
Snapey's avatar

please mark best reply if your problem is solved, and please remember to format your code blocks or we end up with a mess like your last reply

Please or to participate in this conversation.