Forums

Attach File to Thank you email

silkweb 20 Apr, 2010
Hi All, I have read many of the forum items searching for the answer to my question and I thought I was close with a few but need some guidance.

I have 3 documents that will be available for download and I would like people to be able to check 1 2 or all 3 items from 1 form and have the relative attachments sent with the thank you email.

Is this possible? Is so how? If not, can someone explain to me how to at least create 3 forms that will email a specific attachment? I have seen posts that indicate to put some php code in, but it doesn't say where the actual code is supposed to go.

Thank you for your time and patience.

Cheers, S
nml375 20 Apr, 2010
Hi S,
This should be fully possible, but requires some php-coding.
First off, we need access to the CFUploads object for the form:
<?php
$MyForm =& CFChronoForm::getInstance("dbtricks");
$MyUploads =& CFUploads::getInstance($MyForm->formrow->id);
?>


Once we've got this, creating a new attachment is as trivial as adding a string (pointing to the file to attach) to the attachments property array of said object:
<?
$MyUploads->attachments[] = '/path/to/file';
$MyUploads->attachments[] = '/path/to/otherfile';
?>


Now, all we need is some logic to decide which file(s) to attach depending on checkboxes:
<?
//Retrieve the content of the checkboxes, I called 'em "thecheckbox[]" in this example, making them an array suitable for the in_array test further down...
$files = JRequest::get('thecheckbox', array());

//Test whether the value 'file1' was included in the array (of checked checkboxes), if it is, attach the firstFile...
if (in_array('file1', $files)) {
  $MyUploads->attachments[] = '/path/to/firstFile';
}

//Now test whether the value 'file2' was included... if it is, attach the secondFile..
if (in_array('file2', $files)) {
  $MyUploads->attachments[] = '/path/to/secondFile';
}
//and so on...
?>


This would all have to be done within the "On Submit - before Email" code, and you'll probably have to adjust the code to suit your form, form fields, and files.

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