Problems with the "email contact form" - Cookbook

Hi there,

i completely recreated the instruction for a simple contact form like you mentioned here: Email contact form | Kirby CMS

But for some reason if i fill out the form in the frontend, the page just reloads. No errors, no mail sent.

The instruction in Emails | Kirby CMS works for me. I use a smtp server which i reffered in the config.php like that, and it works for me:

  'email' => [
    'transport' => [
      'type' => 'smtp',
      'host' => 'web01.st-srv.eu',
      'username' => 'info@khepri.design',
      'password' => '...',
      'port' => 465,
      'auth' => true,
      'security' => true
    ]
  ]

so doing the following works for me:

  $kirby->email([
    'from' => $from,
    'to' => 'info@khepri.design',
    'subject' => 'Welcome!',
    'body'=> 'It\'s great to have you with us',
  ]);

Did i miss something i have to do for the contact form?

greetings

Did you copy the example to the T? No other page names, field names etc?

Everything the same like mentioned in the example

contact.php in templates.
contact.php in controllers.
contact.yml currently with no content in blueprints.
email.php in templates->emails.
email.html.php in templates->emails.

Could you add a

dump($_POST)

before and after this line in the controller

    if($kirby->request()->is('POST') && get('submit')) {

You should get two arrays showing up after hitting submit.

    dump($_POST);
    if($kirby->request()->is('POST') && get('submit')) {
        dump($_POST);
        // check the honeypot
        if(empty(get('website')) === false) {
            go($page->url());
            exit;
        }
         . . . 

The first array is shown up before hitting send. Its empty. After sending nothing changes. Page reloads and its only one empty array.

Yes, $_POST will be empty when loading the page, that’s normal. But after hitting submit, the first dump should contain the post data (and also the second one, if the if statement is true).

Array
(
    [website] => 
    [name] => Sonja
    [email] => me@example.de
    [text] => Hello from the form                                                                    
    [submit] => Submit
)

I just tested the code in 3.8.0 and its still running fine.

I updatet my system to 3.8.1 and founded the issue (which isnt really a issue).
I noticed the honeypot checker, in the controller, which reloads the page if its triggert.
If i delete this check, everything works and the form gets sent via mail.

The question is now, why ist the honeypot triggert?
Tested it in chrome, brave, firefox, edge. Also via incognitotab.

        if(empty(get('website')) === false) {
            go($page->url());
            exit;
        }

Well, yes, that’s the whole point of the honeypot. If the field is filled in, nothing happens because the field is supposed to remain empty (and hidden)

ahh i get it. I just messed something up while compiling sass, so the field was not hidden. I didnt get that “website” is the honeypot field and filled it out manuelly. I got tricked…
Thanks for your help here.