Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

joedawson's avatar

Button component rendering incorrectly inside email

Hi all,

I currently have the following for a markdown template.

@component('mail::message')
# Hello, {{ $user->forename }}

{{ $email->body }}

@if($email->responsable)
    @component('mail::button', ['url' => route('responses.create', $email)])
        Submit Response
    @endcomponent
@endif
@endcomponent

When the email is sent, the button component is displayed as HTML.

html

But if I remove the if statement around the button the button is rendered as normal.

@component('mail::message')
# Hello, {{ $user->forename }}

{{ $email->body }}

@component('mail::button', ['url' => route('responses.create', $email)])
    Submit Response
@endcomponent
@endcomponent

Any ideas why the button wouldn't be rendered correctly inside of an if statement?

Thanks in advance.

0 likes
4 replies
mindz's avatar

Maybe you can try with slots

I dig up something like this

@component('mail::layout')
    {{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            Header Title
        @endcomponent
    @endslot
{{-- Body --}}
    This is our main message {{ $user }}
{{-- Subcopy --}}
    @isset($subcopy)
        @slot('subcopy')
            @component('mail::subcopy')
                {{ $subcopy }}
            @endcomponent
        @endslot
    @endisset
{{-- Footer --}}
    @slot('footer')
        @component('mail::footer')
            © {{ date('Y') }} {{ config('app.name') }}. Super FOOTER!
        @endcomponent
    @endslot
@endcomponent
joedawson's avatar
joedawson
OP
Best Answer
Level 18

Turned out to be because of indenting.

@if($email->responsable)
    @component('mail::button', ['url' => route('responses.create', $email)])
        Submit Response
    @endcomponent
@endif

Because I'm using Markdown, it's treating the indentation as code block so all I had to do was remove my indents.

@if($email->responsable)
@component('mail::button', ['url' => route('responses.create', $email)])
    Submit Response
@endcomponent
@endif

Except you can still indent inside of the component. Which I find odd.

2 likes

Please or to participate in this conversation.