Contact form: works - but i don't receive Mails

Dear forum

I have already read a lot in the forum and many solutions I could already get from it. I am new to Kirby and much better in CSS and HTML than in PHP.

I have integrated the form from the Cookbook into a website and will customize it later.
When I fill out the form and send it, I get the success message, but no mail arrives.

Hosting has sendmail and/or PHP mail turned on. I tried with and without SMTP.
The form on the test site is here: Kontakt - Schmid Bewegt - Mirjam Schmid - Kinesiologie

site/controllers > kontakt.php

<?php
return function($kirby, $pages, $page) {

    $alert = null;

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

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

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

        $rules = [
            'name'  => ['required', 'minLength' => 3],
            'email' => ['required', 'email'],
            'text'  => ['required', 'minLength' => 3, 'maxLength' => 3000],
        ];

        $messages = [
            'name'  => 'Please enter a valid name',
            'email' => 'Please enter a valid email address',
            'text'  => 'Please enter a text between 3 and 3000 characters'
        ];

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

            // the data is fine, let's send the email
        } else {
            try {
                $kirby->email([
                    'template' => 'email',
                    'from'     => 'info@kunde.ch',
                    'replyTo'  => $data['email'],
                    'to'       => 'info@kunde.ch',
                    'bcc'      => 'ich@designheit.ch',
                    'subject'  => esc($data['name']) . ' – Anfrage Webformular',
                    'data'     => [
                        'text'   => esc($data['text']),
                        'sender' => esc($data['name'])
                    ]
                ]);

            } catch (Exception $error) {
                if(option('debug')):
                    $alert['error'] = 'Das Formular konnte nicht versendet werden: <strong>' . $error->getMessage() . '</strong>';
                else:
                    $alert['error'] = 'Das Formular konnte nicht versendet werden.';
                endif;
            }

            // no exception occurred, let's send a success message
            if (empty($alert) === true) {
                $success = '<h2>Vielen Dank. Wir melden uns in Kürze.</h2>';
                $data = [];
            }
        }
    }

    return [
        'alert'   => $alert,
        'data'    => $data ?? false,
        'success' => $success ?? false
    ];
};

site/snippets > form.php


<?php if($success): ?>
<div class="alert success">
    <p><?= $success ?></p>
</div>
<?php else: ?>
<?php if (isset($alert['error'])): ?>
    <div><?= $alert['error'] ?></div>
<?php endif ?>
<form method="post" action="<?= $page->url() ?>#form" class="uk-form-horizontal uk-margin-large-top">
    <div class="honeypot">
        <label for="website">Website <abbr title="required">*</abbr></label>
        <input type="url" id="website" name="website" tabindex="-1">
    </div>

    <div class="uk-margin field">
        <label class="uk-form-label" for="name">Name *</label>
        <div class="uk-form-controls">
          <input class="uk-input" type="text" id="name" name="name" value="<?= esc($data['name'] ?? '', 'attr') ?>" required>
          <?= isset($alert['name']) ? '<span class="alert error">' . esc($alert['name']) . '</span>' : '' ?>
        </div>
    </div>

    <div class="uk-margin field">
        <label class="uk-form-label" for="email">E-Mail *</label>
        <div class="uk-form-controls">
        <input class="uk-input" type="email" id="email" name="email" value="<?= esc($data['email'] ?? '', 'attr') ?>" required>
        <?= isset($alert['email']) ? '<span class="alert error">' . esc($alert['email']) . '</span>' : '' ?>
        </div>
    </div>
    
    <div class="uk-margin field">
        <label class="uk-form-label" for="text">Mitteilung*</label>
        <div class="uk-form-controls">
          <textarea class="uk-textarea" id="text" name="text" rows="5" required><?= esc($data['text'] ?? '') ?></textarea>
          <?= isset($alert['text']) ? '<span class="alert error">' . esc($alert['text']) . '</span>' : '' ?>
        </div>
    </div>
    <div class="uk-margin">
      <div class="uk-form-controls">
        <button class="uk-button uk-button-secondary uk-width-1-1 uk-width-1-3@l" type="submit" name="submit" value="Submit">Absenden</button>
      </div>
    </div>
</form>
<?php endif ?>

site/templates/emails > email.php

Anfrage Webformular:

<p><?= $text ?></p>
<hr>

<p>Für dieses Angebot interessiere ich mich:</p>

<hr>
<p>Kontakt:</p>
<p><?= $sender ?></p>
<p>
  <?= $email ?>
</p>

Thanks for your support

Welcome to Kirby. Did you check the spam folder in your mailbox?

Hi Stephan
Yes. And I also went through all the spam on the hosting.
I can check again tomorrow if some spam are coming later.

The problem is often that mail ends up in spam, arrives in spam very much later or doesn’t arrive at all depending on spam settings, if the email sender isn’t properly configured (DKIM/SPF settings).

Where are you hosting?

Yes, I had similar problems with the old CMS as well. But the mails always arrived within 15 minutes.

Hosting is with Hoststar in Switzerland.
I have reseller Plesk Access. I assume that I can adjust the DKIM/SPF settings.

So, tomorrow I check the spam folder and ask support if the settings can be optimized.
Thank you.

Might worth looking at the maillog

Something like this should find all occurrences of a address in the log. Obviously change it to the address you sent the mail to

grep someone@example.com /usr/local/psa/var/log/maillog |more

Either SSH into the hosting from a command line or use the terminal in the Plesk panel to run the command.

Another thing… you can also run the domain name through https://mxtoolbox.com/ which should tell you if you have any issues with the DKIM / SPF setup.

I just noticed something in your code above. Its been sometime since i diagnosed email delivery issues but i seem to remember having the from address and to address as the same email being a red flag. Try changing the from address to noreply@kunde.ch or the to address to a google mail address or similar.

Thanks for the MXToolbox, that will help find the problem.
I have anonymized the mail address for this post. But it is correct, I worked with two identical mail addresses. I will try that.

Dear Forum
An e-mail service was active on the hosting (instead of Office365).
The form works now.

Thank you very much for your support.