Keep line breaks on contact form while using esc()

Good afternoon

I am sending an e-mail via

                $kirby->email([
                    'template' => 'contactform',
                    'from'     => esc($data['email']),
                    'replyTo'  => esc($data['email']),
                    'to'       => 'bla@bla.com',
                    'subject'  => esc($data['name']) . ' sent a message from from bla.com',
                    'data'     => [
                        'message'   => esc($data['message']),
                        'sender' => esc($data['name']),
                        ''
                    ]
                ]);

which works perfectly. Except, of course, that in the email, all line breaks of the original input-field/textarea have been escaped/removed. I still want to use esc() since this is a form publicly available on my website but I want to keep the line breaks to make the e-mail more readable.

So how can I have the cake and eat it all?

Thanks
Andreas

In your email template, render the message as

<?= kirbytext($message) ?>

This will keep the line breaks

1 Like