I want to add a generated file as attachment to an email I send.
The problem is, I can’t get the system to add the file to the email.
I use Uniform to send the email from a form. The form works fine without adding the attachment.
The error I get There was an error sending the form: Could not access file: http://kirby.test/reserveren.txt
In the form email action I am trying to attach a kirby page file.
This page can be called in the browser with http://kirby.test/reserveren.txt
Also the reserveren page will give a result.
It just won’t be attached to the email.
What can I do to attach this file (or another generated text file) to the mail?
You are right! The file http://kirby.test/reserveren.txt can be send as attachment.
So, because the file needs to be opened by the browser for it to be created, this method will not work.
The content is an .ics file with the data of an event. The user (my client, the owner of the site) can click the .ics file to easily add an agenda item to their calendar. This file is different for every form-entry from visitors who request a reservation on a date.
I have tried creating a file with $page->createFile() and also $myFile = File::create(). But I couldn’t understand how to fill the parameters and options. Documentation and examples I found could not help me get a grip of how to create a file.
I don’t have a complete solution, but I think if you going down this path $page->createFile() is the right choice. You can either generate the file and attach it directly or you could store it temporarily with some random filename and send a link in the mail, for example: http://kirby.test/e6a97970-3430-4cbd-b358-81e8513ec25b.ics
If you don’t want to create files you could also generate a link in the mail with all parameters attached, like this: http://kirby.test/reserveren?datefrom=xyz&dateto=xyz. When the user clicks the link your content representation .ics could then do it’s magic. But I don’t know how complex the form is and if there’s anything else speaking against it. And it’s a bit back and forth with data.