Open petrus9 opened 2 months ago
This is how it actually shows up in the error screen:
If this provided contact.md
is using the same configuration file from you other issue, there was no value for {{ config.plugins.email.from }}
nor {{ config.plugins.email.to }}
. These were both empty. These need to be provided i a valid email format: https://github.com/getgrav/grav-plugin-email?tab=readme-ov-file#specifying-email-addresses
You said you use "Name lastname email@domain.com)" so I tested with:
process:
email:
subject: "[Site Contact Form] {{ form.value.name|e }}"
from: "Name lastname <email@domain.com>"
to: "Name lastname <email@domain.com>"
...
And it worked totally 100% fine. Even without the quotes its fine:
process:
email:
subject: "[Site Contact Form] {{ form.value.name|e }}"
from: Name lastname <email@domain.com>
to: Name lastname <email@domain.com>
FYI, you should always include a reply_to:
so when you receive an email from the contact form, you can click 'reply' and it will go to the user who entered the form data on your site. Something like:
reply_to: {mail:"{{ form.value.email }}", name:"{{ form.value.name|e }}"}
is the best solution assuming your form has a field for email
and for name
.
Thanks for the reply_to tip. I implemented it and it works!
Here is my new email.yaml
enabled: true
from: 'John Doe <john@johndoe.com>'
to: 'Jane Doe <jane@janedoe.com>'
mailer:
engine: sendgrid
smtp:
server: localhost
port: 25
encryption: none
user: null
password: null
sendmail:
bin: '/usr/sbin/sendmail -bs'
content_type: text/html
debug: false
cc: null
bcc: null
reply_to: null
body: null
Which throws the RFC error
Here is my contact.md which I know does not have any lines for "name:" not sure what I need to fix here so that emails are sent to 'Jane Doe jane@janedoe.com' and come from 'John Doe john@johndoe.com'
title: Contact
heading: 'Say Hello.'
form:
action: /home
name: contact-form
fields:
-
name: name
label: Name
placeholder: Name
type: text
validate:
required: true
-
name: email
label: Email
placeholder: Email
type: email
validate:
required: true
-
name: message
label: Message
placeholder: Message
type: textarea
rows: 6
validate:
required: true
-
name: g-recaptcha-response
label: Captcha
type: captcha
recaptcha_not_validated: 'Captcha not valid!'
buttons:
-
type: submit
value: 'Send Message'
process:
-
captcha: true
buttons: null
-
type: submit
value: 'Send Message'
process: null
-
email:
from:
mail: '{{ config.plugins.email.from }}'
to:
mail: '{{ config.plugins.email.to }}'
reply_to:
mail: '{{ form.value.email }}'
name: '{{ form.value.name|e }}'
subject: '[Contact] Message from {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
-
save:
fileprefix: contact-
dateformat: Ymd-His-u
extension: txt
body: '{% include ''forms/data.txt.twig'' %}'
-
display: thank-you
OH, change your email process: email:
section to:
-
email:
from: '{{ config.plugins.email.from }}'
to: '{{ config.plugins.email.to }}'
reply_to:
mail: '{{ form.value.email }}'
name: '{{ form.value.name|e }}'
subject: '[Contact] Message from {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
You were setting the 'email' only part (mail:
) with the combined email + name. Just set to:
and from:
and you should be fine.
when I change the process: email:
section to your recommendation. I get:
Symfony\Component\Mime\Exception\RfcComplianceException thrown with message "Email "Jane Doe <jane@janedoe.com>" does not comply with addr-spec of RFC 2822."
I am assuming I have to add some kind of name
field, right?
I am following the the formating given in the email plugin interface:
So you have quotes around it? Try removing. Maybe they are not regular quotes.
So you have quotes around it? Try removing. Maybe they are not regular quotes.
No quotes
I’m at a loss 🤷♂️
works for me when I try.
The way it shows up on my screen is like this:
Ya that’s weird. The escaping isn’t right. But I don’t even know how you could do that from a yaml configuration.
The only way I get it to work is if my email.yaml looks like this:
enabled: true
from: 'john@johndoe.com'
to: 'jane@janedoe.com'
mailer:
engine: sendgrid
smtp:
server: localhost
port: 25
encryption: none
user: null
password: null
sendmail:
bin: '/usr/sbin/sendmail -bs'
content_type: text/html
debug: false
cc: null
bcc: null
reply_to: null
body: null
@rhukster so from what you wrote above, it sounds like when you add name and email address to the Email plugin fields like so:
Using:
email:
from: '{{ config.plugins.email.from }}'
to: '{{ config.plugins.email.to }}'
reply_to:
mail: '{{ form.value.email }}'
name: '{{ form.value.name|e }}'
subject: '[Contact] Message from {{ form.value.name|e }}'
body: '{% include ''forms/data.html.twig'' %}'
Your email is delivered coming from John Doe <john@johndoe.com>
and is sent to Jane Doe ,<jane@janedoe.com>
in full
in full name-addr
format? is that what you mean by that you can't replicate this?
When adding the following Name Lastname email@domain.com to the default "to" or "from" I get the following error.
Symfony \ Component \ Mime \ Exception \ RfcComplianceException Email "Name lastname <email@domain.com>" does not comply with addr-spec of RFC 2822. But as far as I am concerned it does comply.
Here is my markdown for the contact form contact.md