Passing variables to a HTML mail template and displaying them

Posted 3 months ago by finchy70

I use the following code to build an email in html. The variables have been passed to the view.

<div>
    <div class="row">
        <h2>
            Vehicle {{ $vehicle->reg }} has failed a vehicle check on {{today()->format('d-m-Y')}}.
        </h2>

    </div>
    <div class="row">
        <h2>
            <span style="color: red">{{Auth::user()->name}}</span> did not tick pass for the following questions.
        </h2>

    </div>

    <hr>
    @foreach($fault_check as $fault)
        <div class="row">
            <h3>{{ $questions[$fault-1]->question }}</h3>
        </div>
    @endforeach

    <hr>
    <h2>Notes Captured</h2>
    <p>{{$notes}}</p>
    <hr>

    Regards,<br>

    <h4>Web Master</h4>
    <h4>EPSConstruction Ltd</h4>
</div>

When the email arrives it looks like this.

Click to see Email

When I use this route to view the email all looks fine.

Route::get('mailable', function () {
    $questions = VehicleQuestion::all();
    $vehicle = App\Vehicle::find(1);
    $faults = [1,5,7,8,9];
    $notes = "It's broken!!!";

    return new App\Mail\FaultsReported($vehicle, $faults, $questions, $notes);
});

Any advice please?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.