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>
<div class="field">
<input type="text" id="name" name="name" placeholder="What're you called?">
</div>
<div class="field">
<input type="email" id="email" name="email" placeholder="Feed me ur email">
</div>
<button id="submit" type="submit" name="submit" value="Submit">Submit</button>
</form>
Controller (intermixed with a few other things from the page)
<?php
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