Having trouble getting email form working

I’m trying to reference this(old) gist for a contact form on Kirby 2, but am having trouble getting it to actually work…

As expected, it doesn’t work locally and throws the mail exception error.
On my staging server, it doesn’t throw any errors at all, but nor do any emails go through. Is there any additional setup in config files or elsewhere that needs to be done?

I have the staging up here
(It’s near the bottom of the top section, typing into “Click me and type some stuff to send a message”)

I modified the gist code a little bit, but think I left the core important stuff untouched. Maybe there’s a chance that I accidentally removed some error code?

Form Snippet
(I have some additional scripting to hide/reveal fields based on input that I hid from here, assuming it has no effect)

 <form id="sayhi" method="post" action="<?= $page->url() ?>/">

  <div class="field">
    <textarea id="text" name="text" oninput="auto_grow(this)" required placeholder="Click me & type some stuff to send a message"></textarea>

  <div class="field">
    <input type="text" id="name" name="name" placeholder="What're you called?">

  <div class="field">
    <input type="email" id="email" name="email" placeholder="Feed me ur email">

  <button  id="submit" type="submit" name="submit" value="Submit">Submit</button>


Controller (intermixed with a few other things from the page)


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

    // get all articles and add pagination
    $articles = page('posts')->children()->flip();

    // contact

    $alert = null;

      if(get('submit')) {
        $data = array(
          'name'  => get('name'),
          'email' => get('email'),
          'text'  => get('text')
        $rules = array(
          'text'  => array('required', 'min' => 0, 'max' => 6666),
        $messages = array(
          'text'  => 'But you didnt even type anything!'
        // 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('email', $data, true);
          // build the email
          $email = email(array(
            'to'      => 'chrs.cblls@gmail.com',
            'from'    => 'chrs.cblls@gmail.com',
            'subject' => 'HI FROM CBLLS.COM',
            'replyTo' => $data['email'],
            'body'    => $body
          // try to send it and redirect to the
          // thank you page if it worked
          if($email->send()) {
            $alert = array('Message sent!!!');
          } else {
            $alert = array($email->error());

    return compact('articles', 'alert');

Any help very appreciated, I’ve been tearing my hair out on this! It doesn’t help that when I started, I was following Kirby 3 docs accidentally :frowning:

It comes up a big “message sent”, though, when I send you a message. The problem with sending mails is often that these mails don’t get through if you have no proper mail server set up or send through a provider.

Hope you have some left? :man_curly_haired:

That’s just because it’s not throwing any errors though, right? So the front-end assumes that it sent, but it hasn’t actually.

So the problem is more likely that I haven’t set up email otherwhere on my server? I didn’t realize it was something that had to be setup, tbh – do you have any advice? It’s an apache server that I have ssh access to…but mildly over my head.

No, if there were any errors and the message wasn’t sent, you wouldn’t get the success message.

I assume the message gets sent but gets blocked by your mail provider.

Still nothing in your inbox? I sent you some mail… Have you also checked your spam folder?

Definitely nothing coming through…it’s my main email, too. Nothing in my spam folder, either.

It’s supposed to be sending to this email from the controller, right?
'to' => 'chrs.cblls@gmail.com',

Maybe you can test this on your server: Kirby Uniform won't send from server (AJAX + Routes)

The to address and from address are identical. Try changing one of them. ive had issues with this in the past. Try setting the from to something like noreply@cblls.com

I think probably gmail is flagging it as spam and either rejecting it or throwing it in the spam folder. Your own server might even be shredding before it leaves because of that.

I think it’s probably a server issue or unsupported or something…I tried changing the from, as well as swapping in a non-gmail throwaway (mailinator) to the to– both no go.

I also tried @texnixe’s debugging command and just got “-bash: log: command not found” :frowning:
Currently waiting for my hosting to respond in their irc, but they’re not great.

Maybe I’m not destined to have a working contact form, it’s kinda just superfluous site procrastination anyways lol

I think so. I never got anything useful through contact forms.

Well, all is not lost. You could try looking at the mailog. There is a good guide here https://mediatemple.net/community/products/dv/204643910/checking-the-mail-log

You can also use the Uniform plugin and set it up as SMTP rather than sending it from the sever.

But yes as @texnixe says and your also resigning your self to it - I had a contact form on my own site for years and never got a single legitimate message throught it. So off it came…

Ah yeah, they don’t allow using the email port I guess– “You can’t use email ports here, you would have to use a relay.”

I’ll just table it for now and maybe try out Uniform for the relay sometime…gotta admit it looked kinda cool though :frowning:

Thanks for the help!

No worries. Personally i would just put an email address up. Use the helper though, so it gets scrambled with str::encode()


Oh yeah, I’ve had my email up at the top under “Say Hi” with a mailto: link, ha – like I said, super superfluous. It was more for the fun ui (it’s a design portfolio) than any practicality, but it’s gotta function still – I’ll find some way to hook it up eventually.

Edit: I wound up hooking the fields up to a google sheet via google scripts, with email notifications turned on.

Disclaimer: not the biggest Php guy.
My question is why did you use the get() shorthand when your forms method is a post request. Thank you for any hints :thinking:

Because: http://k2.getkirby.com/docs/toolkit/api/helpers/get

It’s not $_GET.