Email Uniform config - success alert and email confirmation

Hi there,

First of all, I’m sorry if the topic has already been discussed (If you would point me the first discussion about the subject, that would be perfect). Secondly, I’m not dev, so I may be asking newbie questions. :grin:

I bought this theme called Zeta wich uses Uniform.
I’m actually configuring my contact form. Error alert messages display well but neither success message displays, neither email is sent (I configured the admin email on the panel of course).

Is there a configuration I missed somewhere ?
@mzur you may have an answer I guess ?

I already asked the developer of the theme who politely sent me on the kirby forum…

Thanks :slight_smile:

If you add this code in a template (adjust email addresses):

$success = kirby()->email([
    'from'    => 'welcome@supercompany.com',
    'to'      => 'someone@gmail.com',
    'subject' => 'Welcome!',
    'body'    => 'We will never reply',
])->isSent();
dump($success);

what do you get?

Are you testing this locally or on a remote server? Note that sending email from localhost is often not enabled.

1 Like

Not working better :confused:
This is what my contact.php controller looks like :

<?php

use Uniform\Form;

return function ($kirby) {

  $form = new Form([
    'name' => [
      'rules' => ['required'],
      'message' => 'Comment on vous nomme du coup ?',
    ],
    'email' => [
      'rules' => ['required', 'email'],
      'message' => 'Hmm, ça ne ressemble pas à une adresse e-mail ça…',
    ],
    'subject' => [],
    'message' => [
      'rules' => ['required'],
      'message' => "Avec un message, c'est mieux.",
    ],
  ]);

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

    $form->emailAction([
      'to'       => 'your@email.com',
      'from'     => 'contact@domain.ltd',
      'subject'  => '{{subject}} - from {{name}}.',
      'template' => 'contact',
    ]);
  }

  return compact('form');

};

Though I found out how to edit and display the success alert message

I only suggested you use this code to check if you get a true or false… This was not meant as a solution to your problem.

Oh sorry :grin:
I get a “Cannot use empty array elements in arrays” debugger alert

Where did you put that code? It was meant to be placed inside any template, make sure that is doesn’t interfere with your $success variable from the controller. We only want to test if mails are sent, completely independent from the rest of your code.

I put that in site/controllers/contact.php

Should I place it in site/templates/contact.php for instance ?
I tried but it just prints out the code I copied.

You can put it into any template, if it just outputs the raw code you have probably forgotten the PHP tags. PHP code always has to be inside PHP tags.

I still get the same debugger alert message :

Ah, I just realized there is a typo, for some stupid reason there are two commas after the to email address.

I just the additionnal coma, deleted it.
So now I have a “1” printed in front-end.

I changed for a valid email address but dont get any mail yet…

Ok, 1 means true, so there doesn’t seem to be an error with sending the mail. That the mail does not get through to a real email address is quite normal when sending mail from localhost, because of blackllisting. What you could try and do is install MailHog or a similar app which would intercept your mail and show them in your browser.

Ok great, I’ll test when the site is online :slight_smile:

Thanks for help !

Hi Texnixe,

Indeed, after going online, the contact form sends successfully emails.

Thanks !

Thanks for reporting back, @Nico-liad!