Kishore032's avatar

Only part of html email is rendered by blade

I am having a strange problem and would be grateful if someone can help figure out what's going on

My application is an email forwarding system. Incoming email is delivered through maligun (via a webhook) and stored in a database as body_plain and body_html. And this part works correctly.

In forwarding the email, I use the standard Laravel mailable to add from/to etc and use the build function to attach the html and plain text as follows:

public function build() { return $this -> view('email.body_html') -> text('email.body_plain'); }

The views are:

email/body_html : {!! $email -> body_html !!}} and email/body_plain: {{ $email -> body_plain }}

The emails are sent properly, but only part of the body_html gets sent.

I've tested the view "email/body_html" with:

< ? php dump($email -> body_html) ?>

{!! $email -> body_html !!}

The first statement dumps the whole html correctly, but the second statement renders only a part of the html. The only pattern I have seen is this: If body_html is just an html email body, there is no pattern in what is rendered. But if it is a reply to an html email, then the reply gets rendered correctly, but the original html body does not get rendered at all.

Any idea what I might be doing wrong?

Thanks

0 likes
7 replies
Cronix's avatar
{{!! $email -> body_html !!}

Look at the opening blade there... 2 {'s and 2 !'s. Remove the first {

Kishore032's avatar

That's simply a typing error in the question. That's not the problem.

siangboon's avatar

html opening and closing tag is important, check the original content from the database and compare the output, check and missing or imbalance tags

Kishore032's avatar

Thanks for your suggestion, I've tried everything and did not fix the problem.

Although I have found a different way to implement this, I am still puzzled as to why the two statements below (from the same blade template)

< ? php dump($email -> body_html) ?>

{!! $email -> body_html !!}

would output something quite different.

Snapey's avatar

because one is a dump and the other is echo ?

What are you viewing it in? something that tries to interpret the echoed data?

Kishore032's avatar

It is sent as the body of an email in a mailable, like this:

public function build() { 
    return $this -> view('email.body_html');
}

The view has the code above: a dump that dumps what is being sent just before it is sent. The dump shows the correct contents of the message that's slated to be sent as html. However, the email that is sent receives something different (see my description in my original question).

As far as I have been able to ascertain, this is not a mail/html formatting issue. So even if I do:

< ? php dump($email -> body_html) ?>

{{ $email -> body_html }}

what is dumped is different from what is being sent.

The only patttern I was able to discern is that if the mail is a reply that has the original html embedded, the reply goes through correctly, but not the original html.

Snapey's avatar

Sounds like its just a case of improperly closed tags that is causing the layout to break in some way.

Please or to participate in this conversation.