Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Pass Variable with HTML content to Email View

Tags:

php

email

laravel

I think I'm doing something worng.

I'm trying to pass a variable into an Email View. This varaibvle is read from the database and is configurable via administration page. For some reason, I'm getting the emails without the HTML paser (I see tags like in them) I wanted them to be parsed, so my client can manually change them everytime he wants.

How is that achievable?

My code is:

 Mail::send('emails.contact', array(
        'name' => $request->get('name'),
        'email' => $request->get('email'),
        'user_message' => $request->get('message'),
        'email_content' => html_entity_decode($emailContent->Description)
    ), function($message) use ($result)
    {
        $message->from(env('MAIL_USERNAME'));
        $message->to($result['From'], $result['Name']);
        $message->subject('[Casa Bordeira] We received your message');
    });

An in the view:

<div class="contentEditableContainer contentTextEditable">
  <div class="contentEditable" align='left' >
    <p>
        Hello <strong>{{$name}}</strong>. 
        <br/>
        {{$email_content}}
        <br/>
        <br/>
        <br/>
        Here's a copy of your message:
        <br/>
        <br/>
        {{$user_message}}
    </p>
  </div>
</div>
like image 470
Ricardo Alves Avatar asked Dec 08 '25 17:12

Ricardo Alves


1 Answers

Blade has two different tag styles.

  1. {{ $string }} - this will escape the content using HTML entities.

  2. {!! $string !!} - this does not escape the content and will output the raw HTML value.

See the docs for more information.

like image 198
fubar Avatar answered Dec 11 '25 05:12

fubar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!