getgrav / grav-plugin-email

Grav Email Plugin
http://getgrav.org
MIT License
37 stars 29 forks source link

Multiple E-mail #69

Closed ixlayer closed 3 years ago

ixlayer commented 6 years ago

Cannot sent email, when e-mail is set to multiple. Config: enabled: true from: no-reply@example.com from_name: no-reply to:

rhukster commented 6 years ago

Please paste your YAML snippet in a code block:

```
<paste code here>
```

I can't make any sense of the YAML without it

rhukster commented 6 years ago

Looked at this? https://github.com/getgrav/grav-plugin-email/issues/59#issuecomment-327471648

ixlayer commented 6 years ago
enabled: true
from: no-reply@example.com
from_name: no-reply
to:
  - test@example.com
  - test1@example.com
to_name: test
mailer:
engine: smtp
smtp:
server: smtp.gmail.com
port: 587
encryption: tls
user: no-reply@example.com
password: password
sendmail:
bin: /usr/sbin/sendmail
content_type: text/html
debug: true
           email:
                from: '{{ config.plugins.email.from }}'
                to: ['{{ config.plugins.email.to }}', '{{ form.value.email }}']
                subject: '[Test] {{ form.value.name|e }}'
                body: '{% include ''forms/data.html.twig'' %}'
rhukster commented 6 years ago

ok thanks, i'll take a look

rhukster commented 6 years ago

Works fine for me, i get two emails when i send via mailtrap.io, one to each address.

ixlayer commented 6 years ago

Not works for me :( single:

[2017-11-01 00:47:51] email.DEBUG: ++ Starting Swift_SmtpTransport << 220 mailtrap.io ESMTP ready  >> EHLO myhost.ru  << 250-mailtrap.io 250-SIZE 5242880 250-PIPELINING 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-AUTH PLAIN LOGIN CRAM-MD5 250 STARTTLS  >> AUTH CRAM-MD5  << 334 PDIwMzEyMDE1NzcuMTUwOTQ4NjQ3NEBtYWlsdHJhcC5pbz4=  >> YTMyMjI1MDY3YTM1NTggZTM4MzE2YTk3MzM1M2YyNGEyOTU3OGU5ODk3NDJiMDk=  << 235 2.0.0 OK  ++ Swift_SmtpTransport started >> MAIL FROM:<ineon@mail.ru>  << 250 2.1.0 Ok  >> RCPT TO:<ixlayer@gmail.com>  << 250 2.1.0 Ok  >> DATA  << 354 Go ahead  >>  .  << 250 2.0.0 Ok: queued  [] []

multiple:

[2017-11-01 00:48:33] email.DEBUG: ++ Starting Swift_SmtpTransport << 220 mailtrap.io ESMTP ready  >> EHLO myhost.ru  << 250-mailtrap.io 250-SIZE 5242880 250-PIPELINING 250-ENHANCEDSTATUSCODES 250-8BITMIME 250-DSN 250-AUTH PLAIN LOGIN CRAM-MD5 250 STARTTLS  >> AUTH CRAM-MD5  << 334 PDE3MDI0Mzk3MTguMTUwOTQ4NjUxOEBtYWlsdHJhcC5pbz4=  >> YTMyMjI1MDY3YTM1NTggYWVkNGYyYjhkMzkyNjEyN2Q0NWYwMTE3NmY3ZDNlNzk=  << 235 2.0.0 OK  ++ Swift_SmtpTransport started [] [] 
rhukster commented 6 years ago

Try putting in some manual email addresses rather than from the form (for testing).

rhukster commented 6 years ago

I see the problem, your value for config.plugins.email.to is already an array, so your actually creating an array with another array and a string, hence the error. Let me investigate.

ixlayer commented 6 years ago

direct writed address does not work too

            email:
                from: '{{ config.plugins.email.from }}'
                to: 'test@example.com,test@example.com'
rhukster commented 6 years ago
email:
  from: '{{ config.plugins.email.from }}'
  to: ['test@example.com', 'test@example.com']

works, but i can't get that output to be generated by Twig when there's an array for part of it. If you had only one to in your email config it would work:

user/config/plugins/email.yaml

to: noreply@foo.com
rhukster commented 6 years ago

Ok, i have a crappy way, but it works:

to: ['{{ config.plugins.email.to[0] }}', '{{ config.plugins.email.to[1] }}', '{{ form.value.email }}']

This builds the array manually, so if you ever add another email address in the email config, you would have to update the form to include it.

ixlayer commented 6 years ago

Hello! Only

to: [test@example.com, test1@example.com] 

works for me, not

to: ['{{ config.plugins.email.to[0] }}', '{{ config.plugins.email.to[1] }}']

maybe config.plugins.email.to is not array?

rhukster commented 6 years ago

It's not intended to be an array, but i was trying to get it working as one.

sbmooc commented 5 years ago

I've just run into the same issue, and used the same fix as @rhukster suggested above. Is there a more permanent fix available? Thanks

rhukster commented 5 years ago

The ultimate issue was the author was trying to set an array with another array and a string. Ultimately this has to be output in YAML array format, which is really a string with square brackets. There are other ways to output this. an automated one could be:

to: ["{{ array(config.plugins.to)|merge([form.value.to])| join('","') | raw }}"]

This is will merge the config.plugins.to array with a newly created array with form.value.to in it, then join any array items resulting with ",". Not tested but should work...

sbmooc commented 5 years ago

Thanks @rhukster - will check that out. Much appreciated

NicoHood commented 3 years ago

I guess this can be closed now.