Create page from frontend with mail notification

Hello everyone,

I read and implemented this tutorial: Creating pages from frontend | Kirby CMS (getkirby.com). Everything works great!

Is there a possibility to notify editors of website via mail when an entry is submitted? And what would be best practice to do that? :slight_smile:

Of course.

There is no best practice, I guess. I’d check if page creation was successful (so not already when form is submitted), then send an email. Example of sending email after form submission: Email contact form | Kirby CMS

1 Like

Thanks for the reply, that indeed helped me a lot! Now I got a pretty basic question corresponding to my issue:

I got an e-mail form template with this part:

    <?php $contactPeople = $page->parent()->contact()->toPages(',');
    foreach ($contactPeople as $contact): ?>
      <?php echo str::encode($contact->email()) ?>
    <?php endforeach ?>

This outputs the person that needs to be contacted. The person can vary (for example one person is having vacation, than another one is contact person, sometimes there can be multiple persons).

In e-mail form controller i got this line:

...
        $kirby->email([
                'template' => 'email.html',
                'from'     => 'no-reply@test.net',
                'replyTo'  => $data['email'],
                'to'       => ' HOW TO FETCH MAIL TO HERE ',
                'subject'  => esc($data['name']) . ' - Online-Beratungsanfrage für ' . $page->date()->toDate('%d %B %Y'),
                'data'     => [
                    'date'   => $page->date()->toDate('%d %B %Y'),
                    'text'   => esc($data['text']),
                    'sender' => esc($data['name'])
                ]
...

As you see, I’d like to transform one or multiple mails from template into controller into 'to' => '...', unfortunately I don’t have knowledge how to push it there to controller :see_no_evil:

You can’t push this information from the template to the controller. But why don’t you simply use the same code as in the template, or rather, extract the data from the same source into an array.

Because I don’t know how to :sweat_smile:, I’m still learning php by doing…

$emails = $page->parent()->contact()->toPages(',')->pluck('email', ',', true);

This will give you an array of email addresses from those pages.

1 Like

Thank you for your endless patience, this indeed helped me a lot and I learned again something new.