Hi
I have created a request file form and I would to send a different file to the user based on his choice in the form.
The requested file is selected by a dropdown menu: file1, file2, file3.
The files are in the folder SENDFILES on the server.
In this case if a user select file1, he will receive file1 , if he chooses file2 , he will receive file2 and so on.
I have given a look to FAQ article: How can I attach files from my server to an email in CFv5
But it is not so clear:
What "field_name" and “path” should refert to?
Where I should insert the path of files? And their names?
How can I send different files bases on dropdown selection?
I appreciate if anyone could help me (I’m sorry but I’m not php expert)
Thank you
Giulia
I have created a request file form and I would to send a different file to the user based on his choice in the form.
The requested file is selected by a dropdown menu: file1, file2, file3.
The files are in the folder SENDFILES on the server.
In this case if a user select file1, he will receive file1 , if he chooses file2 , he will receive file2 and so on.
I have given a look to FAQ article: How can I attach files from my server to an email in CFv5
But it is not so clear:
<?php
$form->files["field_name"]["path"] = "ABSOLUTE SERVER PATH TO FILE HERE";
// you can change the "field_name" string to something else
?>
What "field_name" and “path” should refert to?
Where I should insert the path of files? And their names?
How can I send different files bases on dropdown selection?
I appreciate if anyone could help me (I’m sorry but I’m not php expert)
Thank you
Giulia
Hi Guilia,
If the name of your drop-down select is say file_chooser then the result will be available in $form->data['file_chooser'].
So your code would be something like this:
NOTE: the value of $path will depend on your server setup.
Bob
If the name of your drop-down select is say file_chooser then the result will be available in $form->data['file_chooser'].
So your code would be something like this:
<?php
$file_array = array(
'file1' => 'some_file.pdf',
'file2' => 'some_other_file.pdf',
// and so on
);
if ( empty($form->data['file_chooser']) {
returnl
}
$file = $file_array($form->data['file_chooser']);
$path = '...\public-html\. . . \SENDFILES\';
$form->files['file_to_send']['path'] =$path.$file;
?>
Then put file_to_send in the Email action attachments box.
NOTE: the value of $path will depend on your server setup.
Bob
Hi
Sorry for my late feedback, I had to complete other tasks before.
Actually the need is a little bit changed:
I need to send only a file when an user submit to a form, I guess the code is more simple now.
I suppose the code is
<?php
$form->files["my_file.pdf"]["path"] = "...\public-html\SENDFILES\";
// you can change the "field_name" string to something else
?>
Do you confirm?
But where exactly I have to insert thise code?
Sorry for my late feedback, I had to complete other tasks before.
Actually the need is a little bit changed:
I need to send only a file when an user submit to a form, I guess the code is more simple now.
I suppose the code is
<?php
$form->files["my_file.pdf"]["path"] = "...\public-html\SENDFILES\";
// you can change the "field_name" string to something else
?>
Do you confirm?
But where exactly I have to insert thise code?
HI Giulia,
In a Custom Code action in the On Submit event of your form before the Email action.
Bob
In a Custom Code action in the On Submit event of your form before the Email action.
Bob
Ok thank you for your help, I have configured the action.
At moment I cannot test it as I'm working on my local webserver.
At moment I cannot test it as I'm working on my local webserver.
Hi
sorry again if I request support after long time but just today I have the possibility to test this form as I have put the website online.
I have tested the form but I receive only the email with form details (from Admin).
There isn't any email sent to the user with attachment file.
I have surely did some mistake in the configuration.
Please could you help me?
I can provide you privately the access to the website so you can check directly
Let me know
Giulia
sorry again if I request support after long time but just today I have the possibility to test this form as I have put the website online.
I have tested the form but I receive only the email with form details (from Admin).
There isn't any email sent to the user with attachment file.
I have surely did some mistake in the configuration.
Please could you help me?
I can provide you privately the access to the website so you can check directly
Let me know
Giulia
Hi giulia72,
Please post your Custom Code PHP here and please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.
Bob
Please post your Custom Code PHP here and please drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.
Bob
Here it is my custom code (the same code you suggested me above)
<?php
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\";
// you can change the "field_name" string to something else
?>
The DEBUG results are:
Data Array
Array
(
[chronoform] => Download_products_request
[event] => submit
[company_name] => ARC
[First_name] => Giulia
[Family_name] => Magnesa
[Job_title] => web
[Address1] => Lodi
[Address2] =>
[City] => Lodi
[State] =>
[Postal_code] => 12345
[Country] => Italy
[Phone] => 1234
[Email] => g.magnesa@arcinfo.com
[checkbox_group15] => Array
(
[0] => already a customer
)
[comments] =>
[checkbox_license] => 1
[captcha] =>
[button19] => Submit
[ip_address] => 87.0.155.139
)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
[0] => Array
(
[Email] => Array
(
[0] => An email with the details below was sent successfully:
[1] => To:g.magnesa@arcinfo.com
[2] => Subject:Download request
[3] => From name:website pcvuesolutions.com
[4] => From email:arcwebmaster@arcinfo.com
[5] => CC:
[6] => BCC:
[7] => Reply name:
[8] => Reply email:
[9] => Attachments:
[10] => Array
(
)
[11] => Body:
<table>
<tbody>
<tr>
<td>Company</td>
<td>ARC</td>
</tr>
<tr>
<td>First name</td>
<td>Giulia</td>
</tr>
<tr>
<td>Family name</td>
<td>Magnesa</td>
</tr>
<tr>
<td>Job title</td>
<td>web</td>
</tr>
<tr>
<td>Address 1</td>
<td>Lodi</td>
</tr>
<tr>
<td>Address 2</td>
<td></td>
</tr>
<tr>
<td>City</td>
<td>Lodi</td>
</tr>
<tr>
<td>State</td>
<td></td>
</tr>
<tr>
<td>Postal code</td>
<td>12345</td>
</tr>
<tr>
<td>Country</td>
<td>Italy</td>
</tr>
<tr>
<td>Phone</td>
<td>1234</td>
</tr>
<tr>
<td>E-mail</td>
<td>g.magnesa@arcinfo.com</td>
</tr>
<tr>
<td>Required version</td>
<td></td>
</tr>
<tr>
<td>How did you hear about us?</td>
<td>array (
0 => 'already a customer',
)</td>
</tr>
<tr>
<td>Comments</td>
<td></td>
</tr>
</tbody>
</table><br /><br />IP: 87.0.155.139
)
)
[1] => Array
(
[Email] => Array
(
[0] => An email with the details below was sent successfully:
[1] => To:g.magnesa@arcinfo.com
[2] => Subject:Your download request from our site
[3] => From name:ARC informatique
[4] => From email:release@arcinfo.com
[5] => CC:
[6] => BCC:
[7] => Reply name:
[8] => Reply email:
[9] => Attachments:
[10] => Array
(
)
[11] => Body:
Dear Giulia Magnesa
Thank you for your request.
ARC Informatique<br /><br />IP: 87.0.155.139
)
)
)
Also I have received the email
Dear Giulia Magnesa Thank you for your request. ARC Informatique
But any file is attached
<?php
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\";
// you can change the "field_name" string to something else
?>
The DEBUG results are:
Data Array
Array
(
[chronoform] => Download_products_request
[event] => submit
[company_name] => ARC
[First_name] => Giulia
[Family_name] => Magnesa
[Job_title] => web
[Address1] => Lodi
[Address2] =>
[City] => Lodi
[State] =>
[Postal_code] => 12345
[Country] => Italy
[Phone] => 1234
[Email] => g.magnesa@arcinfo.com
[checkbox_group15] => Array
(
[0] => already a customer
)
[comments] =>
[checkbox_license] => 1
[captcha] =>
[button19] => Submit
[ip_address] => 87.0.155.139
)
Array
(
)
Errors
Array
(
)
Debug Info
Array
(
[0] => Array
(
[Email] => Array
(
[0] => An email with the details below was sent successfully:
[1] => To:g.magnesa@arcinfo.com
[2] => Subject:Download request
[3] => From name:website pcvuesolutions.com
[4] => From email:arcwebmaster@arcinfo.com
[5] => CC:
[6] => BCC:
[7] => Reply name:
[8] => Reply email:
[9] => Attachments:
[10] => Array
(
)
[11] => Body:
<table>
<tbody>
<tr>
<td>Company</td>
<td>ARC</td>
</tr>
<tr>
<td>First name</td>
<td>Giulia</td>
</tr>
<tr>
<td>Family name</td>
<td>Magnesa</td>
</tr>
<tr>
<td>Job title</td>
<td>web</td>
</tr>
<tr>
<td>Address 1</td>
<td>Lodi</td>
</tr>
<tr>
<td>Address 2</td>
<td></td>
</tr>
<tr>
<td>City</td>
<td>Lodi</td>
</tr>
<tr>
<td>State</td>
<td></td>
</tr>
<tr>
<td>Postal code</td>
<td>12345</td>
</tr>
<tr>
<td>Country</td>
<td>Italy</td>
</tr>
<tr>
<td>Phone</td>
<td>1234</td>
</tr>
<tr>
<td>E-mail</td>
<td>g.magnesa@arcinfo.com</td>
</tr>
<tr>
<td>Required version</td>
<td></td>
</tr>
<tr>
<td>How did you hear about us?</td>
<td>array (
0 => 'already a customer',
)</td>
</tr>
<tr>
<td>Comments</td>
<td></td>
</tr>
</tbody>
</table><br /><br />IP: 87.0.155.139
)
)
[1] => Array
(
[Email] => Array
(
[0] => An email with the details below was sent successfully:
[1] => To:g.magnesa@arcinfo.com
[2] => Subject:Your download request from our site
[3] => From name:ARC informatique
[4] => From email:release@arcinfo.com
[5] => CC:
[6] => BCC:
[7] => Reply name:
[8] => Reply email:
[9] => Attachments:
[10] => Array
(
)
[11] => Body:
Dear Giulia Magnesa
Thank you for your request.
ARC Informatique<br /><br />IP: 87.0.155.139
)
)
)
Also I have received the email
Dear Giulia Magnesa Thank you for your request. ARC Informatique
But any file is attached
Hi huilia,
The custom code I suggested was this
You need to edit the $path line to include the full path to the folder where your files are; and edit the array to match the values of your drop-down and the corresponding file names.
Bob
PS There was an extra } in the earlier version which I have now removed.
The custom code I suggested was this
<?php
$file_array = array(
'file1' => 'some_file.pdf',
'file2' => 'some_other_file.pdf',
// and so on
);
if ( empty($form->data['file_chooser']) {
returnl
}
$file = $file_array($form->data['file_chooser']);
$path = '...\public-html\. . . \SENDFILES\';
$form->files['file_to_send']['path'] =$path.$file;
?>
Then put file_to_send in the Email Attachments box.
You need to edit the $path line to include the full path to the folder where your files are; and edit the array to match the values of your drop-down and the corresponding file names.
Bob
PS There was an extra } in the earlier version which I have now removed.
Hi Bob
The code you wrote was for my first request.
Now I have only to send a file as the module form is filled (no dropdown menu selected). Sorry for the confution I had to open a new topic.
Also what do you mean:
1. Then put file_to_send in the Email Attachments box. ..the field Attachment files in Email To user action?
2.You need to edit the $path line to include the full path to the folder where your files are; and edit the array to match the values of your drop-down and the corresponding file names. ... My file is in SENDFILES folder and I wrote
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\"; ...is it correct?
The code you wrote was for my first request.
Now I have only to send a file as the module form is filled (no dropdown menu selected). Sorry for the confution I had to open a new topic.
Also what do you mean:
1. Then put file_to_send in the Email Attachments box. ..the field Attachment files in Email To user action?
2.You need to edit the $path line to include the full path to the folder where your files are; and edit the array to match the values of your drop-down and the corresponding file names. ... My file is in SENDFILES folder and I wrote
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\"; ...is it correct?
Hi Bob
maybe there is a confusion as I not use anymore dropdown box and different files to send based on chosen option.
My fault: I had to open a new topic
Now I have a simple form (no array) and when it is filled it must send an answer with attacched file in the email.
The code I used is:
<?php
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\";
// you can change the "field_name" string to something else
?>
Is it correct?
my_file.pdf is in SENDFILES folder. Do I have to change anything in the code?
Regarding your comment: "Then put file_to_send in the Email Attachments box" Do you mean to insert the "my_file.pdf" file name in Attachment field of Email Action? In this case it is just done
maybe there is a confusion as I not use anymore dropdown box and different files to send based on chosen option.
My fault: I had to open a new topic
Now I have a simple form (no array) and when it is filled it must send an answer with attacched file in the email.
The code I used is:
<?php
$form->files["my_file.pdf"]["path"] = "...\SENDFILES\";
// you can change the "field_name" string to something else
?>
Is it correct?
my_file.pdf is in SENDFILES folder. Do I have to change anything in the code?
Regarding your comment: "Then put file_to_send in the Email Attachments box" Do you mean to insert the "my_file.pdf" file name in Attachment field of Email Action? In this case it is just done
Hi guilia72,
I wrote: $form->files["my_file.pdf"]["path"] = "...\SENDFILES\"; ...is it correct?
No, an adapted version of my example is
Bob
[[>> later : fixed error with slashes - see later post <<]]
I wrote: $form->files["my_file.pdf"]["path"] = "...\SENDFILES\"; ...is it correct?
No, an adapted version of my example is
<?php
$file = 'my_file.pdf';
$path = JPATH_SITE.'/SENDFILES/';
$form->files['file_to_send']['path'] =$path.$file;
?>
Then add file_to send in the Attachments box of the Email action.
Bob
[[>> later : fixed error with slashes - see later post <<]]
Hi Bob
just to inform you, I have found the solution:
There was a mistake in your code :
you wrote \SENDFILES\ instead of /SENDFILES/.
So the code is:
<?php
$file = 'my_file.pdf';
$path = JPATH_SITE.'/SENDFILES/';
$form->files['file_to_send']['path'] =$path.$file;
?>
thank you
Giulia
just to inform you, I have found the solution:
There was a mistake in your code :
you wrote \SENDFILES\ instead of /SENDFILES/.
So the code is:
<?php
$file = 'my_file.pdf';
$path = JPATH_SITE.'/SENDFILES/';
$form->files['file_to_send']['path'] =$path.$file;
?>
thank you
Giulia
This topic is locked and no more replies can be posted.