Sending emails with array data throws "Undefined variable..."

I want to send an email to one recipient that contains array data.

For this I want to use a template that loops over the array data such as

Self-Check Report

<? foreach($questions_and_answers as $entry): ?>
    <p>Frage:<?= $entry['question'] ?></p>
    <p>Antworten:</p>
    <? foreach($entry['answers'] as $key => $value): ?>
        <p><?= $value . ': ' . $key ?></p>
    <? endforeach; ?>
<? endforeach; ?>

However kirby->email() throws the exception: “Undefined variable $entry”.

Is it not possible to use foreach in email templates?

Are you using these short tags everywhere? They are usually discouraged.

Thanks for replying.

You can in fact not use “<?” shortags in email template context.

Strangly “<?=” works.

Update:
Read a little about the history of short tags and it seems that “<?” was deprecated in php 8.0.

I got a little confused there. Anyway. Thanks for replying.

That is the short echo tag and is fine to use but should only be used for echoing stuff, so your code should look like this:

<?php foreach($questions_and_answers as $entry): ?>
    <p>Frage:<?= $entry['question'] ?></p>
    <p>Antworten:</p>
    <?php foreach($entry['answers'] as $key => $value): ?>
        <p><?= $value . ': ' . $key ?></p>
    <?php endforeach; ?>
<?php endforeach; ?>

Yeah! I now read that. I’m a bit rusty when it comes to php. Thank you for taking the time for explaining.