Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Forms - sending file as email attachment not working

Started by Muut Archive 10 years ago · 7 replies · 1289 views
10 years ago

Hello, i updated grav with all plugins to latest version and now, sending uploaded file from from as email attachement is not working, i receive email without any attachments. This is my page with form:

YAML
title: Form page
form:
    name: email-form
    fields:
        - name: message
          label: 'write message
          placeholder: 'your message...'
          type: textarea
          validate:
            required: true

        - name: email
          label: 'e-mail'
          placeholder: 'e-mail address'
          autocomplete: 'off'
          type: email
          validate:
            required: true 

        - name: attachfile
          label: 'Attach file'
          type: file
          multiple: false
          avoid_overwriting: true

    buttons:
        - type: submit
          value: 'send'
        - type: reset
          value: 'resettt'

    process:
        - email:
          from: '{{ config.plugins.email.from }}'
          to: ['{{ form.value.email }}']
          subject: 'Sample mail'
          body: '{% include ''forms/data.html.twig'' %}'
          attachments: [attachfile]

        - message: 'Message was sent'

I am using antimatter theme, but the theme is not updated for support with forms 2.0 so i added {% include "forms/fields/formname/formname.html.twig" %} like it is in plugin's template. Can you help me? Thanks

10 years ago

I am running email v2.5.0, form v2.0.3 and antimatter v2.0.0. When i submit the form, i get this error:

PHP
TypeError
Argument 1 passed to Grav\Plugin\EmailPlugin::buildMessage() must be of the type array, null given, called in \user\plugins\email\email.php on line 74
10 years ago

Could be an indentation problem in the YAML form definition. The form parameters under email: cannot be found.

10 years ago

you were right, this fixed sending form :) but attachments are still not working, i recieve email with text input values, but no attachement. I also tried uploading .exe file and it sent email, but i have configured plugin to accept only image types.

10 years ago

Can you please open an issue on the email plugin repository? Better place to track bugs

10 years ago

finally found it, issue was on my side and it is working now. But i prefer old upload without ajax, it is possible to use classic input field without javascript? thanks

10 years ago

It's really not possible. It did 'work' before in basic usage, but fell apart quickly when used in complex scenarios like in list items. Without Ajax, the file upload happens when the form is submitted, and any errors etc (especially nested in other fields) are very hard to handle cleanly when repopulating the form for example. it's just too messy and required so many workarounds and cludges we decided to rewrite that field entirely with a much cleaner and simpler ajax solution.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1360 9 years ago
Archive · by Muut Archive, 9 years ago
2 939 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2958 9 years ago
Archive · by Muut Archive, 9 years ago
3 1122 9 years ago