Admin, Email and Forms

Hello, new to Grav…have a couple of questions and issues I am trying to resolve.

  1. Email plugin is not saving the settings I set in Admin. I had to manually configure email.yaml. Not a big deal but was wondering if I missed something. Any ideas as to why this would be happening or am I misunderstanding how the admin UI works?
  2. Contact Form on my site is not working properly with email. Everything seems to be configured properly, email test works from cli, but the form seems to not follow the settings in email.yaml for authentication to my SMTP server. In email.log, it shows it is trying PLAIN auth type instead of tls. Why is this happening and how can I make sure it follows the configuration set?

Here are the files in question:

email.yaml

enabled: true
from: 'biz-inquiry@*******'
to: 'biz-inquiry@*******'
mailer:
  engine: smtp
  smtp:
    server: 'smtp.protonmail.ch'
    port: 587
    encryption: tls
    user: 'biz-inquiry@*******'
    password: '***************'
  sendmail:
    bin: '/usr/sbin/sendmail -bs'
content_type: text/html
debug: true

Contact Form:

title: 'Contact Me'
subtitle: 'Find out more information'
section_classes: 'bg-gray-100 dark:bg-gray-800 py-8 md:py-24'
title_text: auto
form:
    name: contact
    action: '#contact-us'
    inline_errors: true
    fields:
        name:
            label: Name
            display_label: false
            placeholder: 'Your full name'
            autocomplete: 'on'
            type: text
            validate:
                required: true
        email:
            label: Email
            display_label: false
            placeholder: 'Your email address'
            type: email
            validate:
                required: true
        phone:
            label: Phone
            display_label: false
            placeholder: 'Your phone number (optional)'
            type: text
        message:
            label: Message
            display_label: false
            placeholder: 'Your message'
            type: textarea
            rows: 4
            validate:
                required: true
    buttons:
        submit:
            type: submit
            classes: 'no-default-style text-white bg-gray-700 hover:bg-primary'
            value: 'Submit Form'
    process:
        email:
            from: '{{ config.plugins.email.from }}'
            to:
                - '{{ config.plugins.email.to }}'
                - '{{ form.value.email }}'
            subject: '[Contact Form] {{ form.value.name|e }}'
            body: '{% include ''forms/data.html.twig'' %}'
        save:
            fileprefix: feedback-
            dateformat: Ymd-His-u
            extension: txt
            body: '{% include ''forms/data.txt.twig'' %}'
        message: '<b>Thanks!</b> We''ve received your enquiry and will get back to you very soon...'
        reset: true

email.log (when submitting contact form):

[2023-10-24 21:27:15] email.INFO: Email sent to [“biz-inquiry@","youseenothing@”] at 2023-10-24 21:27:15 → :stop_sign: Failed to authenticate on SMTP server with username “biz-inquiry@********” using the following authenticators: “PLAIN”. Authenticator “PLAIN” returned “Expected response code “235” but got code “535”, with message “535 5.7.8 Error: authentication failed: authentication failed”.”.

email.log (when using email test from cli):

[2023-10-24 20:45:11] email.INFO: Email sent to ["kf5u@"] at 2023-10-24 20:45:11 → :white_check_mark: < 220 mailsub003.protonmail.ch ESMTP Postfix > EHLO [127.0.0.1] < 250-mailsub003.protonmail.ch < 250-PIPELINING < 250-SIZE 36480000 < 250-STARTTLS < 250-ENHANCEDSTATUSCODES < 250-8BITMIME < 250 CHUNKING > STARTTLS < 220 2.0.0 Ready to start TLS > EHLO [127.0.0.1] < 250-mailsub003.protonmail.ch < 250-PIPELINING < 250-SIZE 36480000 < 250-AUTH PLAIN < 250-ENHANCEDSTATUSCODES < 250-8BITMIME < 250 CHUNKING > AUTH PLAIN Yml6LWlucXVpcnlAa2Y1dS5uZXQAYml6LWlucXVpcnlAa2Y1dS5uZXQATkhZNFk5VldGRjVDSDc2Rg== < 235 2.7.0 Authentication successful > MAIL FROM:<biz-inquiry@> < 250 2.1.0 Ok > RCPT TO:<kf5u@******> < 250 2.1.5 Ok > DATA < 354 End data with . > . < 250 2.0.0 Ok: queued as 4SFWvn6HrKz7QTXW

Here is the output from running the email test from the cli:

Current Configuration:

^ Grav\Common\Data\Data^ {#253
  #gettersVariable: "items"
  #items: array:6 [
    "enabled" => true
    "from" => "biz-inquiry@*******"
    "to" => "biz-inquiry@*******"
    "mailer" => array:3 [
      "engine" => "smtp"
      "smtp" => array:5 [
        "server" => "smtp.protonmail.ch"
        "port" => 587
        "encryption" => "tls"
        "user" => "biz-inquiry@*******"
        "password" => "**************6F"
      ]
      "sendmail" => array:1 [
        "bin" => "/usr/sbin/sendmail -bs"
      ]
    ]
    "content_type" => "text/html"
    "debug" => true
  ]
  #blueprints: null
  #storage: null
  -missingValuesAsNull: false
  -keepEmptyValues: true
  #nestedSeparator: "."
}

Message sent successfully!

Any help or guidance would be greatly appreciated. Also, FWIW, I am using the Typhoon theme and Grav v1.7.43 - Admin v1.10.43. Thanks in advance for your time and help!

1 Like

@kf5u, My first hunch tells me this might be caused by Grav’s feature Environment Configuration.

Grav searches for config files in the following locations:

  1. System/core configs in /system/config/
    (Do not ever touch these)
  2. Plugin/themes provided configs in /user/plugins/myplugin/myplugin.yaml, resp. /user/themes/mytheme/mytheme.yaml
  3. Which may be overridden by configs found in /user/config/
  4. Which in turn may be overridden by domain based configs in either /user/env/mydomain.com/config/, or /user/mydomain.com/config/

You said:

Email plugin is not saving the settings I set in Admin. I had to manually configure email.yaml.

Where Admin saves config files depends on how Admin is being accessed.

  • When using ‘localhost’ it will save configs in location 3.
  • When using mydomain.com it will save configs in location 4.

Questions:

  • In which location(s) do you find file email.yaml ?
  • In which location did you manually edit email.yaml ?
    I guess you edited email.yaml in location 3.

Considering the above:

  • When using CLI, Grav is unaware of a domain and will try to find email.yaml in location 3.
    Note: You can override this behaviour by providing the environment to the CLI using $ bin/plugin email test-email -t test@email.com --env=mydomain.com
  • When using a form, the form is accessed in the browser using ‘localhost’ or a domain, hence Grav will search for email.yaml in either location 3. or resp. location 4.

First, thank you for the response!

Locations are:

./user/plugins/email/email.yaml
./user/config/plugins/email.yaml

I edited the second one manually because I understand the environment configuration in Grav.

The env piece is not what is effecting this. Interestingly enough though, out of the blue, this morning it is working. Crazy that it just started working. Saves are working and email is sending. Could this be a cache thing? So odd.

I’ve never experienced this, but it could have been. Is it still working? Really not sure if this should be marked resolved until we get to the bottom of it.

The only other suggestion I might have made before this mysteriously worked for you was to hardcode some of your mail settings into the form to help you troubleshoot.

Special note though: this is how all questions should be asked @kf5u!! It lead to a productive thread discussion, too. Well done! I wish there was an award I could offer you for this. Welcome to the community, please stay. :star:

It is definitely still working. Just very odd but it is continuing to work as expected now. I wouldn’t know if I should mark this resolved as the oddity happened and there had to be a cause. I wouldn’t think something like this would just randomly happen, unless I was just tripping over my own toes working through troubleshooting steps too fast and not paying attention to cache.

Funny you mention this…I did exactly that in one of my tests and it didn’t work then either. That was when I moved on to coming here to ask, as I was stumped.

I appreciate the kind words. Thanks for making me feel welcome and I will definitely be around.

1 Like