Simple Email Contact Form


Is there a simple solution or guide to create a contact me email form in Kirby 3?


There is an older version for Kirby 2, with the help of the email documentation, you should be able to adapt that.

Here are the gists for Kirby 2

In the controller, you have to change lines 34 to 53 and use the new email engine instead. The rest should be basically the same.

I’ve put it on the up next list for the cookbook.


Thank you @texnixe

Just to confirm, am I changing this:

  // create the body from a simple snippet
      $body  = snippet('contactmail', $data, true);
      // build the email
      $email = email(array(
        'to'      => '',
        'from'    => '',
        'subject' => 'New contact request',
        'replyTo' => $data['email'],
        'body'    => $body
      // try to send it and redirect to the
      // thank you page if it worked
      if($email->send()) {
      // add the error to the alert list if it failed
      } else {
        $alert = array($email->error());

to this:

try {
    'from' => '',
    'replyTo' => '',
    'to' => '',
    'cc' => '',
    'bcc' => '',
    'subject' => 'Welcome!',
    'body'=> 'It\'s great to have you with us',
} catch (Exception $error) {
  echo $error;

But with my own email obviously :slight_smile:


Yep, and in the controller return function with the $kirby variable:

return function($kirby) {

You can also check out the fork by which has some useful enhancements, like storing the value in case an error appears so that the form is not emptied all the time and a little honeypot.


A working example is now in review in case you are still struggling:


I set this up but after filling in the details all I get is *The form could not be sent * :frowning:


Hm, did you set up the email templates both for HTML and plain text? Since its failing in the try-catch block, there seems to be something wrong in the email setup.


Same issue here.
If I have email.text.php and email.html.php the form can’t be sent. I need to have a email.php and it works fine.