Forums

Problem with attaching dynamic file to email

goliath 30 May, 2013
I encounter a problem with attaching a dynamic file to email. I must be doing something wrong because it is not working here (no attachment).

Some more details...

The name of my form is testform1

I put in a 'HTML to PDF' action with the following details:

Document/File name = <left empty>
View = Save to server
Document save path = /var/www/vhosts/mywebsite/httpdocs/files
File name in Data/Files array: form1

When there is a document in the httpdocs/files directory called testform1_20130528152759.pdf I can put in the action 'Email [GH]' the value /var/www/vhosts/mywebsite/httpdocs/files/testform1_20130528152759.pdf in the Attachments field. This works fine.

My question is what to fill in when using a dynamic document name? It can't be that hard, but I can't find it.

Very many thanks in advance!
gabedaly 01 Jun, 2013
If I remember correctly, you need to give the HTML to PDF a "name for the form data array" and then you can use {myname} in the email action(GH).
goliath 04 Jun, 2013
So if you translate this to my situation, I use the name "form1".

In the 'HTML to PDF' I put:

Document/File name = <left empty>
View = Save to server
Document save path = /var/www/vhosts/mywebsite/httpdocs/files
File name in Data/Files array: form1

In the 'Email [GH]' I put:

File Attachments: {form1}

This doesn't work. What am I doing wrong? Somebody has to know??
goliath 07 Jun, 2013
Anyone please??
GreyHead 07 Jun, 2013
Hi geertmartens,

Please add a Debugger action to see what is in the $form->data array. I suspect that {form1} either gives you just the file name or the full 'file data' array. What you need in the Email action is the path to the file e.g. /var/www/vhosts/mywebsite/httpdocs/files/file_name.ext

Bob
goliath 07 Jun, 2013
Bob, if you have to translate your answer to my example:

In the 'HTML to PDF' I put:

Document/File name = <left empty>
View = Save to server
Document save path = /var/www/vhosts/mywebsite/httpdocs/files
File name in Data/Files array: form1

Correct?

What is the exact path to the file in Email [GH]?
File Attachments = /var/www/vhosts/mywebsite/httpdocs/files/form1 ? Or what?
GreyHead 07 Jun, 2013
Hi geertmartens,

Please add a Debugger action to see what is in the $form->data array.

I have no idea what the path is without all of the information :-(

Bob
goliath 07 Jun, 2013
Array
(
[option] => com_chronoforms
[chronoform] => testform1
[event] => submit
[Itemid] =>
[name] => Joe
[country] => Belgium
[input_submit_3] => Submit
[2aabbfe32e031c63e9e20b48fad012b6] => 1
)
Validation Errors:
Array
(
)
Debug Data
Email info
Email sent successfully
From: (Admin at mywebsite) info@mywebsite
To: me@mywebsite
Subject: Test
Email body
You may customize this message under the 'Template' tab in the Email settings box.
Submitted by 12.123.456.78
/var/www/vhosts/mywebsite/httpdocs/files/testform1_20130607162046.pdf has been uploaded OK.
gabedaly 08 Jun, 2013
It looks like your file name is testform1 not form1
/var/www/vhosts/mywebsite/httpdocs/files/testform1_20130607162046.pdf has been uploaded OK. Try using {testform1} in the email action if that's the name you want for your file. If not, read on.
What I have done for my site is place a custom code before the HTML to PDF with the following:
<?php
$form->data['mtg_service_agreement'] = $form->data['pdf_file_name'] = $form->data['lastname']."_".$form->data['firstname']."_mtg_service_agreement";
?>

This sets the file name to mtg_service_agreement with the users last and first names right before that for example:
Daly_Gabe_mtg_service_agreement.
In the HTML to PDF action I use mtg_service_agreement as the "File name in Data/Files array" and in the email GH action I use {mtg_service_agreement} as the file to attach.

The HTML to PDF action searches in the array for the field "pdf_file_name". If that isn't set than it looks for the name in the action itself. If that IS set then it uses that and adds the timestamp to the end but, if that's not set it uses the form name with a timestamp.
Hope this helps
goliath 11 Jun, 2013
Thanks gabedaly for your reply.
But I am affraid this doesn't seem to work.

First I tried using {testform1} in the email action but with no effect.
Second I tried your script as mentioned below. I changed 'lastname' in 'name' and 'firstname' in 'country' (the fields I use).

Still no file attached to mail.

Data Array:
Array
(
[option] => com_chronoforms
[chronoform] => testform1
[event] => submit
[Itemid] =>
[name] => test
[country] => test
[input_submit_3] => Submit
[7db1e168a14969edd952af5287203485] => 1
[pdf_file_name] => test_test_mtg_service_agreement
[mtg_service_agreement] => test_test_mtg_service_agreement
)
Validation Errors:
Array
(
)
Debug Data
Email info
Email sent successfully
From: (Admin at mywebsite) info@mywebsite
To: me@mywebsite
Subject: Test
Email body
You may customize this message under the 'Template' tab in the Email settings box.
Submitted by 12.123.456.78
/var/www/vhosts/mysite/httpdocs/files/test_test_mtg_service_agreement.pdf has been uploaded OK.
goliath 11 Jun, 2013
Update: If I resubmit my form again (with the same data) it seems the file is attached then. So it seems that first the mail is sent and after that the file is uploaded!? Any suggestions?
GreyHead 11 Jun, 2013
Hi geertmartens,

Is the Upload Files action before or after the Email action? It needs to be before.

Bob
goliath 11 Jun, 2013
Well, let's say I have NO 'Upload files' action in my form... but it uploads my file anyhow (see /var/www/vhosts/mywebsite/httpdocs/files/test_test_mtg_service_agreement.pdf has been uploaded OK.)

So I put this action before the 'Email [GH]' action?

What do I put in the Fields configuration and in the Upload path? And what to put in the Array fields?
goliath 12 Jun, 2013
Is there anyone who can say me which actions I need to achieve this and in which order to put them??

Now I use:

1) Custom code
<?php
$form->data['mtg_service_agreement'] = $form->data['pdf_file_name'] = $form->data['name']."_".$form->data['country']."mtg_service_agreement";
?>

2) HTML to PDF
View = Save to server
Document save path = /var/www/vhosts/mywebsite/httpdocs/files/
File name in Data/Files array = pdf_file_name

3) Email [GH]
Action label = <empty>
File Attachments = /var/www/vhosts/mywebsite/httpdocs/files/{pdf_file_name}.pdf


I have NO Upload files action. Do I need this? Because if I check the debugger I can see /var/www/vhosts/mywebsite/httpdocs/files/test_test_mtg_service_agreement.pdf has been uploaded OK. Doesn't that mean the file was uploaded successfully? The only problem I have is that the form sends the mail BEFORE the file is uploaded.

And if I have to use the Upload files action, where to put it and WHAT to put in there?

Anyone, please!?
gabedaly 12 Jun, 2013
Is your HTML to PDF before the email action? It should be. There is no need for the file uploader action. I don't use it. The way I have the actions is like so:

First: Custom code to set the file name
Second: HTML to PDF with mtg_service_agreement as the File name in Data/Files array ( I think pdf_file_name will work too)
Last: Email action with {mtg_service_agreement} as the attachment name

Are your actions order similar?
Just re-read your last post and it seems you have the actions in the correct order. One thought, on the HTML to PDF do you have the "Mode" set to controller? This is how I have it set. I think if it's set to view, it doesn't fire until all the other actions have fired first. Definitely check that out.
goliath 13 Jun, 2013
Hi gabedaly

I checked that out. The mode was set to 'View' and not to 'Controller'. I changed this and now it executes the uploading first but there is still no attachment sent.

I'm getting desperate...
gabedaly 13 Jun, 2013
Can you try to remove the path to save file and just leave it blank in both the HTML to PDF and Email action and then use {mtg_service_agreement} in the email. This is exactly how I have it set. Otherwise I'm out of thoughts.
I'm thinking there may be an issue with your upload path. I never tried to save it to another location, I just let Chronoforms save it in it's own folder on the server (/public_html/components/com_chronoforms/pdf/my_form_name) and it works fine.
GreyHead 17 Jun, 2013
Hi gabedaly,

I just wrote and posted this FAQ about the PDF action; I got email attachment and adding a link to an email working . . . but I had to add a little bug-fix* to the action to do that. It's in the last section of the manual.

Bob

* My version of the action is quite old so Max may have fixed this in the current versions.
This topic is locked and no more replies can be posted.