---
title: 'Trying to attach file to email with error'
url: 'https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520'
markdown: 'https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520.md'
date: '2026-06-21'
description: 'My contact form is modular and sending email with and without a file is working. Files are saved to the folder and I am receiving emails. Now I want to add the'
---

[General](https://getgrav.org/forum/general)

#   Trying to attach file to email with error 

 Solved by pamtbaau [View solution](https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520#post-41359)

  Started by Duc 6 months ago · 3 replies · 757 views    

 [6 months ago](https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520#post-41358 "Permalink") 

My contact form is modular and sending email with and without a file is working. Files are saved to the folder and I am receiving emails. Now I want to add the file to the email as an attachment, but getting this error when I add the `attachments: resume` under process.

error:

```php
Whoops \ Exception \ ErrorException (E_WARNING)
Undefined array key "path"

/var/www/httpd/jcb/user/plugins/email/email.php
                break;
        }
    }

    protected function sendFormEmail($form, $params, $vars, $event)
    {
        // Build message
        $message = $this->email->buildMessage($params, $vars);
        $locator = $this->grav['locator'];

        if (isset($params['attachments'])) {
            $filesToAttach = (array)$params['attachments'];
            if ($filesToAttach) foreach ($filesToAttach as $fileToAttach) {
                $filesValues = $form->value($fileToAttach);

                if ($filesValues) foreach($filesValues as $fileValues) {
                    if (isset($fileValues['file'])) {
                        $filename = $fileValues['file'];
                    } else {
                        $filename = $fileValues['path'];
                    }

                    $filename = $locator->findResource($filename, true, true);

                    try {
                        $message->attachFromPath($filename);
                    } catch (\Exception $e) {
                        // Log any issues
                        $this->grav['log']->error($e->getMessage());
                    }
                }
            }
        }

        //fire event to apply optional signers
        $this->grav->fireEvent('onEmailMessage', new Event(['message' => $message, 'params' => $params, 'form' => $form]));

        // Send e-mail

         $status = $this->email->send($message);

Arguments
"Undefined array key "path""

```

the form:

```yaml
form:
  name: email/jobs
  action: /job
  fields:
    name:
      id: name
      label: Name
      classes: 'form-control form-control-lg'
      placeholder: 'Enter your name'
      autocomplete: 'on'
      type: text
      validate:
        required: true
    email:
      id: email
      classes: 'form-control form-control-lg'
      label: Email
      placeholder: 'Enter your email address'
      type: email
      validate:
        rule: email
        pattern: "^\w([\w\.+-]*[\w-])?@([\w-]+\.)+[a-z]{2,5}$"
        required: true

    resume:
      label: Resume
      destination: 'user/data/email/jobs/uploads'
      type: file
      multiple: true
      autofocus: false
      limit: 5
      accept:
        - application/pdf
        - .docx
        - .doc

    message:
      label: Message
      classes: 'form-control form-control-lg'
      size: long
      placeholder: 'Enter your message'
      type: textarea
      validate:
        required: true
    captcha:
      type: turnstile
      theme: light

  buttons:
    submit:
      type: submit
      value: Submit
      classes: 'btn btn-primary btn-block'
    reset:
      type: reset
      value: Reset
      classes: 'btn btn-primary btn-block'

  process:
    turnstile: true
    upload: true
    email:
      from: '{{ config.plugins.email.from }}'
      to:
        - '{{ config.plugins.email.from }}'
      subject: '[Job Inquiry] {{ form.value.name|e }}'
      body: "{% include 'forms/data.html.twig' %}"
      attachments:  ## <---- THE ERROR HAPPENS WHEN THIS IS ADDED
        - resume    ## < ---- THE ERROR HAPPENS WHEN THIS IS ADDED
    save:
      fileprefix: 'job-inquiry-[{{ form.value.name|e }}]-'
      dateformat: Ymd-His-u
      extension: txt
      body: "{% include 'forms/data.txt.twig' %}"
    message: 'Your email was sent successfully.'
    display: thank-you-inquiry

```

 [6 months ago](https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520#post-41359 "Permalink")  Solution 

@duceduc, I can reproduce the error using your form definition.

However...

- What's the purpose of action `upload: true`?
    There is no action "upload" defined by the email plugin. See <https://learn.getgrav.org/17/forms/forms/reference-form-actions>.
    Did you create a custom action? If so, what's the code of it?
- When removing action `upload: true` the form works fine. The email is send with attachment.

 👍 2 

 [6 months ago](https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520#post-41361 "Permalink") 

Thank you. I don't have such custom action. That line may have been added from trying other codes to get file upload working.

 [6 months ago](https://getgrav.org/forum/general/trying-to-attach-file-to-email-with-error-t520#post-41363 "Permalink") 

If the answer above solved your problem, please mark it as a solution 🙏

[Log in](https://getgrav.org/login?return=%2Fforum%2Fgeneral%2Ftrying-to-attach-file-to-email-with-error-t520) to reply.

###  Suggested topics

 | Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| [SSL-Error](https://getgrav.org/forum/general/ssl-error-t9502)    [General](https://getgrav.org/forum/general) · by Hanns Mattes, 5 days ago |  | 0 | 85 | [5 days ago](https://getgrav.org/forum/general/ssl-error-t9502 "by Hanns Mattes") |
| [localhost, Windows, bin/grav server: core upgrade deletes system/router.php, and bin/grav disappears after the server is stopped](https://getgrav.org/forum/general/localhost-windows-bin-grav-server-core-upgrade-deletes-system-router-php-and-bin-grav-disappears-after-the-server-is-stopped-t9495)    [General](https://getgrav.org/forum/general) · by Dima, 1 week ago |  | 1 | 113 | [1 week ago](https://getgrav.org/forum/general/localhost-windows-bin-grav-server-core-upgrade-deletes-system-router-php-and-bin-grav-disappears-after-the-server-is-stopped-t9495 "by pamtbaau") |
| [Proposal to list Commercial Themes + Plugins in GPM. Your thoughts are requested...](https://getgrav.org/forum/general/proposal-to-list-commercial-themes-plugins-in-gpm-your-thoughts-are-requested-t9490)    [General](https://getgrav.org/forum/general) · by pamtbaau, 2 weeks ago |  | 0 | 186 | [2 weeks ago](https://getgrav.org/forum/general/proposal-to-list-commercial-themes-plugins-in-gpm-your-thoughts-are-requested-t9490 "by pamtbaau") |
| [Multi-site health/status monitor for GRAV](https://getgrav.org/forum/general/multi-site-health-status-monitor-for-grav-t9425)    [General](https://getgrav.org/forum/general) · by lynbor, 2 months ago |  | 5 | 694 | [3 weeks ago](https://getgrav.org/forum/general/multi-site-health-status-monitor-for-grav-t9425 "by lynbor") |
| [Unified Login system - you might need to reset your password](https://getgrav.org/forum/general/unified-login-system-you-might-need-to-reset-your-password-t9463)    [General](https://getgrav.org/forum/general) · by Andy Miller, 1 month ago |  | 0 | 417 | [1 month ago](https://getgrav.org/forum/general/unified-login-system-you-might-need-to-reset-your-password-t9463 "by Andy Miller") |
