Page 1 of 1

UDT, attach formbuilder file upload to email

Posted: Tue May 26, 2015 6:44 pm
by KayakMan
Hey,

I have another thread that this option can solve.... if I can attach a file uploaded through Formbuilder with a UDT and send it via CMSMailer. Note, files are being uploaded.

Note: 'Deny file to be attached with emails', is unticked.

Can anyone see a problem in my UDT with the file upload/attachment:

$actparams = $smarty->get_template_vars('actionparams');
$form_id = $actparams['form_id'];

if($form_id == 5) {
$mail = cms_utils::get_module('CMSMailer');

{* -- my file upload is {$attachcv} / {$fld_53} -- *}

if(!empty($params['fld_53'])) {
$fileupload = $params['fld_53'];
} else {
$fileupload = '';
}


$subject = " here ";
$body = " body of email ";
$mail->AddAddress( $destination );
$mail->IsHTML( true );
$mail->SetBody( $body );
$mail->SetSubject( $subject );
$mail->AddAttachment('$fileupload', 'PDF file', 'base64', 'application/pdf');
$mail->Send();
$mail->reset();
}

Also see http://forum.cmsmadesimple.org/viewtopi ... =8&t=67308

Re: UDT, attach formbuilder file upload to email

Posted: Tue May 26, 2015 9:30 pm
by KayakMan
Also a file is attached to emails when using a non UDT submission e.g.
'Email Results to set Address(es)'.

Re: UDT, attach formbuilder file upload to email

Posted: Tue May 26, 2015 9:34 pm
by KayakMan
I've tried the following:

//Attach an image file
//$mail->AddAttachment($file);
//$mail->AddAttachment($_fileupload['file']['tmp_name'], $_fileupload['file']['name']);

//$mail->AddAttachment("/uploads/cvs/$fileupload");

$mail->AddAttachment($path/$fileupload, 'PDF file', 'base64', 'application/pdf' );

Re: UDT, attach formbuilder file upload to email

Posted: Tue May 26, 2015 11:16 pm
by KayakMan
Okay, getting there :-)

This works. But my emailed PDFs are corruptly encoded.. they won't load ???.


$remote_path = 'http://www.domain.com/$fileupload';

$mail->AddStringAttachment($remote_path, $fileupload, $encoding = 'base64', $type = 'application/octet-stream');

Re: UDT, attach formbuilder file upload to email

Posted: Wed May 27, 2015 2:35 pm
by PinkElephant
KayakMan wrote: $mail->AddAttachment('$fileupload', 'PDF file', 'base64', 'application/pdf');
Looks like quoting the $fileupload variable passes '$fileupload' rather than the intended value.

(The docs suggest the AddAttachment method returns a boolean for success/failure so an if() might help deal with a bad path, etc).