Contact Form not working

Hi all,
i am working on my first kirby based project. it is based on kirby 2.5.10 and the beautiful kompas theme. i tried to build a contact form, but in the end no mail is sent.
the theme contains some styling for forms, obviously without further functionality.
therefore, i tried to follow this: https://gist.github.com/bastianallgeier/c396df7923848912393d
do you have any hints what could be going wrong?
the page can be seen here for the moment: http://vbbsk.de/cms/contact
hoster is hosteurope.
do you need further information?
thank you in advance,
carsten

Hi, I think you are missing the action attribute on your element in the template.
Add it like this: action="<?= $page->url()?>

hi, thank you for your suggestion!
unfortunately, it did not solve the problem. still, no mail is sent.
as discribed here, the form should work nearly out of the box:
https://www.guenter-duba.at/news/einfaches-kontaktformular-fuer-kirby

i’ll try to paste my actual code of templates/contact.php:

<?php snippet('header') ?>

  <main class="main wrap" role="main">

      <div class="row">
          <div class="col-12">
              <?php echo $page->text()->kirbytext() ?>
          </div>
      </div>

      <div class="row">
          <div class="col-12">
              <form action="<?= $page->url() ?>" method="post" class="form">

                    <div class="row">
                        <div class="col-6">
                            <label for="name">Ihr Name? <abbr title="required">*</abbr></label>
                            <input type="text" id="name" name="name" placeholder="Name" />
                        </div>

                        <div class="col-6">
                            <label for="email">Ihre E-Mail-Adresse? <abbr title="required">*</abbr></label>
                            <input type="email" id="email" name="email" placeholder="E-Mail" />
                        </div>
                    </div>

                  <div class="cf"></div>

                  <label for="text">Schildern Sie uns Ihre Anliegen: <abbr title="required">*</abbr></label>
                  <textarea id="text" name="text" required placeholder="Ihre Nachricht" rows="3"></textarea>

                  <div class="cf"></div>
                  <div class="links">
                    <p>Mit einem Klick auf Absenden erklären sich damit einverstanden, dass Ihre Daten zur Bearbeitung Ihres Anliegens verwendet werden. Weitere Informationen und Widerrufshinweise finden Sie in der Datenschutzerklärung.</p>
                  </div>

                  <input class="button-primary" type="submit" name="submit" value="Absenden">

              </form>
          </div>
      </div>

    </div>

  </main>

<?php snippet('footer') ?>

Well, but where is the rest of the code? The contact form as such is pretty useless, you need a controller that takes care of dealing with the form input and if everything is correct, actually. send the mail.

Can you post your controller’s code too + is it getting called when you submit the form?

Does your hosting provider support PHP sendmail? Does it. work if you send an email from the CLI using sendmail?

Simple test example:

echo "Subject: test" | /usr/lib/sendmail -v me@domain.com

Get.the correct path to be used in the line above

which  sendmail

(seems to be /usr/sbin/sendmail on hosteurope, according to the info below)

If you followed the tutorial you mentioned above to the T, you might also want to check these docs on hosteurope:

1 Like

i took the code as is from github. just changed mail adresses.
here is the code in site/controllers/contact.php:

<?php

return function($site, $pages, $page) {

  $alert = null;

  if(get('submit')) {

    $data = array(
      'name'  => get('name'),
      'email' => get('email'),
      'text'  => get('text')
    );

    $rules = array(
      'name'  => array('required'),
      'email' => array('required', 'email'),
      'text'  => array('required', 'min' => 3, 'max' => 3000),
    );

    $messages = array(
      'name'  => 'Bitte geben Sie einen Namen ein',
      'email' => 'Bitte geben Sie eine Mailadresse ein',
      'text'  => 'Bitte geben Sie Ihre Nachricht ein'
    );

    // some of the data is invalid
    if($invalid = invalid($data, $rules, $messages)) {
      $alert = $invalid;

    // the data is fine, let's send the email
    } else {

      // create the body from a simple snippet
      $body  = snippet('contactmail', $data, true);

      // build the email
      $email = email(array(
        'to'      => 'post@vbbsk.de',
        'from'    => 'post@vbbsk.de',
        'subject' => 'Neue Nachricht',
        'replyTo' => $data['email'],
        'body'    => $body
      ));

      // try to send it and redirect to the
      // thank you page if it worked
      if($email->send()) {
        go('contact/thank-you');
      // add the error to the alert list if it failed
      } else {
        $alert = array($email->error());
      }

    }

  }

  return compact('alert');

};

BTW. Do you get any error messages?

Is debugging on?

Have you tried what. I suggested above?

Do you get the thank-you page? On. your site it seems that the form itself doesn’t really work because I don’t get any error messages and the validators do not work.

yippieh!
now it is working. the code was okay, but it was the missing standard mail adress in hosteurope’s configuration. after setting this, everything is working fine.
thank you a lot for this decisive hint!
good night, carsten