Forums

Attach a CSV file and send it by Email

Fioretta 10 Jan, 2013
Hi, I have a similar problem: I need to attach a CSV file to the email with the form data.
Can I do that from the "Custom PHP code" > "Before Emails Code" field?
Where I can find the PHP object that manage the email? Or docs about that?

Thanks in advance =)
GreyHead 10 Jan, 2013
Hi Fioretts,

It's not all that similar so I've split your post out from the XML thread.

Where does your CSV file come from?

It it's a fixed file you can use my Custom Email [GH] action to attach it. If it's created in the form you may be able to add it to the form files array and attach it that way.

Bob
Fioretta 10 Jan, 2013
It's a single row CSV with the form data that I have to create with something like that
<?php
// some variables
$filename = 'attachment.csv';
$filepath = 'tmp/';
// creating the CSV row
$csv_row = $form->data['field1'] . "," . $form->data['field2'];
// saving it in the file
$file = fopen ($filepath . $filename, 'w');
fwrite ($file, $csv_row);
fclose ($file);
// adding the file to the email as attachment
/* TODO */
?>


Where I can find your custom email action? Tried to search in the forum, but no success...

I've also noticed "Attachments fields name" field in the email form, but can't understand how it works. May be suitable for me?


Thank you very much for the reply! ^^
GreyHead 10 Jan, 2013
Hi Fioretta,

I've just written a little FAQ that should give you the code for this:
Please see this FAQ

Bob
This topic is locked and no more replies can be posted.