PHP Mailer in Kirby

For the files that pertain to the contact form, I copied the code from Kirby docs as it is and only added my email in the kontakt.php which lives inside the controller folder.

The email.html.php file lives inside the emails folder which lives inside the templates folder. It has this code which I found in the instruction you sent:

Hello Company,

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

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

<p>Best,</p>
<p><?= $sender ?></p>

I added tel to the controller as follows:

<?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'),
            'tel'  => get('tel'),
            'text'  => get('text')
        ];

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

        $messages = [
            'name'  => 'Please enter a valid name',
            'email' => 'Please enter a valid email address',
            'tel' => 'Please enter a valid phone number',
            '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'     => 'myemail@gmail.com',
                    'replyTo'  => $data['email'],
                    'to'       => 'myemail@gmail.com',
                    'subject'  => esc($data['name']) . ' sent you a message from your contact form',
                    'data'     => [
                        'text'   => esc($data['text']),
                        'sender' => esc($data['name'])
                    ]
                ]);

            } catch (Exception $error) {
                if(option('debug')):
                    $alert['error'] = 'The form could not be sent: <strong>' . $error->getMessage() . '</strong>';
                else:
                    $alert['error'] = 'The form could not be sent!';
                endif;
            }

            // no exception occurred, let's send a success message
            if (empty($alert) === true) {
                $success = 'Your message has been sent, thank you. We will get back to you soon!';
                $data = [];
            }
        }
    }

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

and the debugger displayed the message: The validator does not exist: tel

There isn’t a tel validator:

Instead you can use minLength, maxLenght or match (regex) to validate tel input.

Thank you :slightly_smiling_face:

I was able to make the contact form work and the issue with the file names has also been solved.