Buy Now
Sign in

How to send email with the database CSV Export file as attachment

skalounas , September 20 2017
S
skalounas
How to send an email with the database CSV Export file as an attachment?
Is it also possible to automate it using maybe an internal function or even a cron job?
admin
Hi skalounas,

Automating any form page needs a cron task pointed to the form event url:
link_to_form&event=event_name


What you need to do is to create a "Read data" action to read the records, then a "CSV" action to "Save the file" then call the saved file path in the "Attachments" box in the "Email" action.

The "Data provider" in the "CSV" should be set to {var:read_data_name.[n].Model_Name}, the text in bold needs to match your read data settings.

The "Attachments" box in the email should have:
{var:csv_name.path}

Which is going to reference the file created by the csv

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
S
skalounas
Dear MAx

Thank you for your answer.

I follow your instructions in a test form with only a send button. The table with the data already exists in the database (and is filled in by another form and has already data).

When I click the send button:

1. A download starts and it downloads a csv file with only this inside:
<b>Warning</b>: fputcsv() expects parameter 2 to be array, null given in <b>/home/futuren9/public_html/kemeiedeorg/libraries/cegcore2/admin/extensions/chronofc/functions/csv/csv_output.php</b> on line <b>17</b><br />

2. The email is never send.

What I input in each part is:

1. In read data action (model name: Data3) I choose the appropriate db table. All the rest are left in default.
2. In csv action, I choose as Data Provider the Data3 and as Action: Download (when everything will be ok, I will change it to Store). The rest I leave in default (except the file name and storage path, that now are: ListaYpopsifion.csv and {path:front}/csv/ListaYpopsifion.csv
3. In the email action I input my email and subject and in attachment list this: {path:front}/csv/ListaYpopsifion.csv

Where is the mistake?

mik
admin
Hi mik,

The "Data provider" of the CSV is wrong, please use this:

{var:read_data_name.[n].Data3}

Make sure to change the "read_data_name" to the name of your "Read data" action.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
S
skalounas
Great! Thank you Max.

Now the csv gets downloaded and with all the correct data in it.

Still, the email is never been sent. Any ideas?

mik
admin
Hi mik,

Please check wit ha debugger after the email action, it will show you if the email has been sent or not, you can post the debugger section of the email here.

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
S
skalounas
Dear Max

Thank you for your answer. I have put the debugger in the setup, but for some reason, the page load forever, so I can't even see the debug info.

Here's the test form:
http://www.kemeiede.org/administrator/index.php?option=com_chronoforms6&cont=manager&chronoform=test

After "send" the page loads forever.

mik
admin
Hi mik,

Yes, because you have a download CSV action, this halts any screen output, please set the CSV to "Store file"

Best regards
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
S
skalounas
Dear Max

Thank you for your answer. I did as you said. You can see for yourself now, the debug info. Here's the test form:

http://www.kemeiede.org/administrator/index.php?option=com_chronoforms6&cont=manager&chronoform=test

mik
admin
Hi mik,

The website is secured by login, please copy the debug results here

Best regards,
Max
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
S
skalounas
Here it is:

Error saving the csv file.

Warning: fopen(/home/futuren9/public_html/kemeiedeorg/components/com_chronoforms6/chronoforms/csv/ListaYpopsifion.csv): failed to open stream: No such file or directory in /home/futuren9/public_html/kemeiedeorg/libraries/cegcore2/libs/file.php on line 23

Array
(
[option] => com_chronoforms6
[cont] => manager
[chronoform] => test
[event] => submit
[text2] => testtesttest
[Κατέβασμα_αρχείου_csv] =>
[_ga] => GA1.2.1027829385.1506681195
[_gid] => GA1.2.1018099907.1507526974
[c1a37326484447a99d3ce08357fc23f2] => 888e6b5ecbd0305f1c8fcf832646aa03
)

Array
(
[read_data3] => Array
(
[log] => Array
(
[0] => SELECT `Data3`.`aid` AS `Data3.aid`, `Data3`.`user_id` AS `Data3.user_id`, `Data3`.`created` AS `Data3.created`, `Data3`.`modified` AS `Data3.modified`, `Data3`.`Επώνυμο` AS `Data3.Επώνυμο`, `Data3`.`Όνομα` AS `Data3.Όνομα`, `Data3`.`ΌνομαΠατρός` AS `Data3.ΌνομαΠατρός`, `Data3`.`ΗμνίαΓέννησης` AS `Data3.ΗμνίαΓέννησης`, `Data3`.`ΤόποςΓέννησης` AS `Data3.ΤόποςΓέννησης`, `Data3`.`Χώρα` AS `Data3.Χώρα`, `Data3`.`Υπηκοότητα` AS `Data3.Υπηκοότητα`, `Data3`.`Αρδελτίου` AS `Data3.Αρδελτίου`, `Data3`.`Ημνίαέκδοσης` AS `Data3.Ημνίαέκδοσης`, `Data3`.`ΕκδούσαΑρχή` AS `Data3.ΕκδούσαΑρχή`, `Data3`.`Οδός` AS `Data3.Οδός`, `Data3`.`Αριθμός` AS `Data3.Αριθμός`, `Data3`.`Πόλη` AS `Data3.Πόλη`, `Data3`.`ΤΚ` AS `Data3.ΤΚ`, `Data3`.`differentaddress` AS `Data3.differentaddress`, `Data3`.`ΟδόςΕπικοινωνίας` AS `Data3.ΟδόςΕπικοινωνίας`, `Data3`.`ΑριθμόςΕπικοινωνίας` AS `Data3.ΑριθμόςΕπικοινωνίας`, `Data3`.`ΠόληΕπικοινωνίας` AS `Data3.ΠόληΕπικοινωνίας`, `Data3`.`ΤΚΕπικοινωνίας` AS `Data3.ΤΚΕπικοινωνίας`, `Data3`.`Τηλέφωνο` AS `Data3.Τηλέφωνο`, `Data3`.`Κινητό` AS `Data3.Κινητό`, `Data3`.`Email` AS `Data3.Email`, `Data3`.`τόποςφοίτησης` AS `Data3.τόποςφοίτησης`, `Data3`.`Ίδρυμαφοίτησης1` AS `Data3.Ίδρυμαφοίτησης1`, `Data3`.`Ίδρυμαφοίτησης2` AS `Data3.Ίδρυμαφοίτησης2`, `Data3`.`ΑναγνώρισηΔΟΑΤΑΠ` AS `Data3.ΑναγνώρισηΔΟΑΤΑΠ`, `Data3`.`ΆλλοιΤίτλοι` AS `Data3.ΆλλοιΤίτλοι`, `Data3`.`Ξένηγλώσσα1` AS `Data3.Ξένηγλώσσα1`, `Data3`.`ΠιστοποιητικόΓλώσσας1` AS `Data3.ΠιστοποιητικόΓλώσσας1`, `Data3`.`ΠιστοποιητικόΓλώσσας1α` AS `Data3.ΠιστοποιητικόΓλώσσας1α`, `Data3`.`Ξένηγλώσσα2` AS `Data3.Ξένηγλώσσα2`, `Data3`.`ΠιστοποιητικόΓλώσσας2` AS `Data3.ΠιστοποιητικόΓλώσσας2`, `Data3`.`ΠιστοποιητικόΓλώσσας2α` AS `Data3.ΠιστοποιητικόΓλώσσας2α`, `Data3`.`ΓραπτηΕξεταση` AS `Data3.ΓραπτηΕξεταση`, `Data3`.`Πιστοποίησηεμπειρίας` AS `Data3.Πιστοποίησηεμπειρίας`, `Data3`.`ΌνομαΣυστ1` AS `Data3.ΌνομαΣυστ1`, `Data3`.`ΕπώνυμοΣυστ1` AS `Data3.ΕπώνυμοΣυστ1`, `Data3`.`ΒαθμίδαΣυστ1` AS `Data3.ΒαθμίδαΣυστ1`, `Data3`.`ΕκπΊδρυμαΣυστ1` AS `Data3.ΕκπΊδρυμαΣυστ1`, `Data3`.`EmailΣυστ1` AS `Data3.EmailΣυστ1`, `Data3`.`ΌνομαΣυστ2` AS `Data3.ΌνομαΣυστ2`, `Data3`.`ΕπώνυμοΣυστ2` AS `Data3.ΕπώνυμοΣυστ2`, `Data3`.`ΒαθμίδαΣυστ2` AS `Data3.ΒαθμίδαΣυστ2`, `Data3`.`ΕκπΊδρυμαΣυστ2` AS `Data3.ΕκπΊδρυμαΣυστ2`, `Data3`.`EmailΣυστ2` AS `Data3.EmailΣυστ2`, `Data3`.`Λογοι` AS `Data3.Λογοι`, `Data3`.`ΕνημερωθήκατεΑπο` AS `Data3.ΕνημερωθήκατεΑπο` FROM `azh9g_chronoengine_chronoforms_data_Aitisi_Symmetohis` AS `Data3` LIMIT 100;
)

[var] => Array
(
[0] => Array
(
[Data3] => Array
(
[aid] => 3
[user_id] => 0
[created] => 2017-08-03 08:49:06
[Επώνυμο] => ΛΑΜΠΡΟΥ
[Όνομα] => ΕΥΑΓΓΕΛΙΑ
[ΌνομαΠατρός] => ΔΗΜΗΤΡΙΟΣ
[ΗμνίαΓέννησης] => 09/08/1968
[ΤόποςΓέννησης] => ΧΑΛΚΙΔΑ
[Χώρα] => ΕΛΛΑΔΑ
[Υπηκοότητα] => ΕΛΛΗΝΙΚΗ
[Αρδελτίου] => ΑΚ 773036
[Ημνίαέκδοσης] => 17/09/2013
[ΕκδούσαΑρχή] => ΑΤ ΝΕΑΣ ΙΩΝΙΑΣ
[Οδός] => ΠΟΝΤΟΥ
[Αριθμός] => 5
[Πόλη] => ΑΘΗΝΑ
[ΤΚ] => 14232
[differentaddress] => Ίδια με τη διεύθυνση κατοικίας
[ΟδόςΕπικοινωνίας] =>
[ΑριθμόςΕπικοινωνίας] =>
[ΠόληΕπικοινωνίας] =>
[ΤΚΕπικοινωνίας] =>
[Τηλέφωνο] => 2102773677
[Κινητό] => 6942271753
[Email] => evalamprou@hotmail.gr
[τόποςφοίτησης] => Προπτυχιακές σπουδές στο Εσωτερικό
[Ίδρυμαφοίτησης1] => ΕΘΝΙΚΟ ΚΑΠΟΔΙΣΤΡΙΑΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΑΘΗΝΩΝ_ΟΙΚΟΝΟΜΙΚΩΝ ΕΠΙΣΤΗΜΩΝ
[Ίδρυμαφοίτησης2] =>
[ΑναγνώρισηΔΟΑΤΑΠ] =>
[ΆλλοιΤίτλοι] => ΠΙΣΤΟΠΟΙΗΤΙΚΟ ΠΑΙΔΑΓΩΓΙΚΗΣ ΚΑΙ ΔΙΔΑΚΤΙΚΗΣ ΕΠΑΡΚΕΙΑΣ
[Ξένηγλώσσα1] => ΓΕΡΜΑΝΙΚΑ
[ΠιστοποιητικόΓλώσσας1] => Ναι
[ΠιστοποιητικόΓλώσσας1α] => ΚΡΑΤΙΚΟ ΠΙΣΤΟΠΟΙΗΤΙΚΟ ΓΛΩΣΣΟΜΑΘΕΙΑΣ (Β2)
[Ξένηγλώσσα2] => ΑΓΓΛΙΚΑ
[ΠιστοποιητικόΓλώσσας2] => Όχι
[ΠιστοποιητικόΓλώσσας2α] =>
[ΓραπτηΕξεταση] =>
[Πιστοποίησηεμπειρίας] => Ναι
[ΌνομαΣυστ1] => ΕΥΘΥΜΙΟΣ
[ΕπώνυμοΣυστ1] => ΛΙΑΤΣΟΣ
[ΒαθμίδαΣυστ1] => ΕΚΠΑΙΔΕΥΤΙΚΟΣ
[ΕκπΊδρυμαΣυστ1] => ΦΡΟΝΤΙΣΤΗΡΙΟ Μ.Ε.
[EmailΣυστ1] => xrimakliatsos@gmail.com
[ΌνομαΣυστ2] =>
[ΕπώνυμοΣυστ2] =>
[ΒαθμίδαΣυστ2] =>
[ΕκπΊδρυμαΣυστ2] =>
[EmailΣυστ2] =>
[Λογοι] => Παράλληλα με τις γνώσεις που απόκτησα από την παιδαγωγική επάρκεια στο Πανεπιστήμιο σας, θέλω να εξοπλιστώ και με τις απαραίτητες γνώσεις, εμπειρίες και δεξιότητες στην Κριτική Παιδαγωγική.
Να προετοιμαστώ στην έρευνα, στην μάθηση και διδασκαλία μέσα απ
[ΕνημερωθήκατεΑπο] => Μέσα κοινωνικής δικτύωσης
)

)

here there are simiral debug data, of al lthe applications that exist in the db

Then at the end there is this:



[email5] => Array
(
[recipients] => Array
(
[0] => mihalisd@gmail.com
)

[subject] => ListaYpopsifion csv
[body] => a
<table width="100%" cellpadding="5" cellspacing="3" border="0" class="ui table"><tr><td width="30%" valign="top" align="right"><strong>Text label</strong></td><td width="70%" valign="top" align="left">testtesttest</td></tr></table>
[files] => Array
(
[0] => /home/futuren9/public_html/kemeiedeorg/components/com_chronoforms6/chronoforms/csv/ListaYpopsifion.csv
)

[from_name] => test
[from_email] => mihalisandroid@gmail.com
[result] => the Mail could not be sent.
[var] =>
)

)
admin
Hi,

Apologizes for the late reply!

It looks like there is a problem saving the file due to permissions or something else, but the email is configured correctly, but it also reports that it could not be sent, which means that there is some issue with the mail server, please try to remove the csv file from the email attachments and check if the email can be sent ?

Best regards
Max
If your main question got answered then please mark the answer using the button!​

Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!