Forums

How can I attach files from my server to an email in cfv6?

gmarra7 19 Jun, 2018
Answer
Hi, I'm trying to use this Custom Code

<?php
$path = JPATH_SITE.'/components/com_chronoforms5/uploads/folder_name/';
$form->files['field_name']['path'] = $path.'file_name.jpg';
?>

but it does not seem to work with Chronoforms v6.
The problem is that the email does not start,
in fact the debugger gives me this view: files] => Array
(
[0] => guide
)

[result] => the Mail could not be sent.

Thanks to everyone who wants to help me
GreyHead 20 Jun, 2018
Hi gmarra,

If this is the same file each time you can add the full file path to the Attachments list box in the Email action.

Bob
Ron 31 Jan, 2019
Hello

This is an old thread but my issue is the same. I have a dropdown choice list that the visitor can chose from as to what he needs to download. As per the choice an email goes to the visitor with the chosen file as an attachment.

I used this code in CFV5 successfully:
    <?php 
switch ($_POST['select1'])
{
case 'File 1':
$form->files['catalog'] = array(
'path' => '/home/xyz/public_html/cat/file1.pdf'
);
break;
case 'File 2':
$form->files['catalog'] = array(
'path' => '/home/xyz/public_html/cat/file2.pdf'
);
break;

}

?>
I cannot seem to succeed in doing it in CFV6.

I used a custom code block with this code and named it as "attach_file" and in the attachment list of the email I added {var:attach_file} but I do not get it to work.. The email is sent successfully but without any attachment.

Please suggest where am I going wrong.

Thanks

Ron
Ron 31 Jan, 2019
This thread seems to be marked as answered. Hope this post is noticed ??
healyhatman 31 Jan, 2019
switch($this->data("field_name"))

and
$this->set("var_name", "value")
and use {var:var_name} in the email attach files field. Or just return the file path string, and use {var:phpname}

Or use a switch action, data source {data:fieldname}, returning the path (shouldn't need to be an array unless you're needing to upload multiple files)
Ron 01 Feb, 2019
Hello healyhatman,

Thanks for the help. You mean my code should be like this :
    <?php 
switch($this->data("select1"))
{
case 'File 1':
$this->set('attach_file', 'value') = array(
'path' => '/home/xyz/public_html/cat/file1.pdf'
);
break;
case 'File 2':
$this->set('attach_file', 'value') = array(
'path' => '/home/xyz/public_html/cat/file2.pdf'
);
break;

}

?>

Well it does not work and the submission hangs on submit. The debugger does not show anything. Maybe I am making a mistake somewhere.

Ron
healyhatman 01 Feb, 2019
No, where it says"value" you should put the value. And you should use the dropdown value not label in the switch cases
Ron 01 Feb, 2019
Okay. So you mean this way ?
    <?php
switch ( $this->data( "File 1" ) ) {
case 'File 1':
$this->set( 'attach_file', 'File 1' ) = array(
'path' => '/home/xyz/public_html/cat/file1.pdf'
);
break;
}

switch ( $this->data( "File 2" ) ) {
case 'File 2':
$this->set( 'attach_file', 'File 2' ) = array(
'path' => '/home/xyz/public_html/cat/file2.pdf'
);
break;

}
?>
healyhatman 01 Feb, 2019
No. Put the value you are setting. No =
$this->set("var_name", "the actual value you want var_name to be");
healyhatman 01 Feb, 2019
But really just use a switch action (not event switcher). What you're doing doesn't need to be done in PHP.
Ron 01 Feb, 2019

But really just use a switch action (not event switcher). What you're doing doesn't need to be done in PHP.


I know switcher could be easy. But I don't know haw to put the values there. I tried reading the manual but could not het it to work.

Thanks

Ron
healyhatman 01 Feb, 2019
Really?

Data source should be {data:dropdownfieldname}
Then you have
optionvalue:texttoreturn
So you would for example have
file1:path/to/the/file.pdf

By the way your switch syntax is all over the place.
Ron 01 Feb, 2019
WOW.. Thanks.
This is what was confusing me. I am going to try now.

Thanks again..

Ron
Ron 01 Feb, 2019
Hello healyhatman,

The debugger gives this output but no email is being sent :



Thanks for all the help

Ron
healyhatman 01 Feb, 2019
And what have you put in the attach files box in the email action
Ron 01 Feb, 2019
I have a custom code for my email body. named "for_email" and in email body I call it by {var:for_email} The switch is named "attach_file" and in Attachments list I added {var:attach_file}
healyhatman 01 Feb, 2019
And you have the switch set to return var only?
Ron 01 Feb, 2019
Yes I have done that :
healyhatman 01 Feb, 2019
Does the file actually exist at the location specified
What error does the debug show
Ron 01 Feb, 2019
Yes the file exists. CFV5 works at this moment. The debugger shows no error.. I sent a screen shot in earlier post,

Thanks
healyhatman 01 Feb, 2019
The debugger you sent shows nothing, send the whole thing. Copy paste.
Ron 01 Feb, 2019
Hello healyhatman

I sent you a pm.. Please see it.

Thanks
Ron 02 Feb, 2019
Hello,

The switch block may not work as it takes the path as an email. So the email sending fails and no attachment is establishes. I tried with custom code and also with php block. Nothing seems to work.

Any help I would greatly appreciate.

Thanks
Ron
healyhatman 02 Feb, 2019
I replied to your PM. Check your file location. What do you mean it "takes the path as an email"?

Try just putting the path to one file directly in the file attach list and see if it sends
Ron 02 Feb, 2019

Try just putting the path to one file directly in the file attach list and see if it sends



Okay . I am going to do this.
Thanks for all the help.

Ron
Ron 05 Feb, 2019
Hello,

Could not succeed in attaching any file. If I add anything in the attach Attachments settings it stops sending email.

I don't know what more to do.
healyhatman 05 Feb, 2019
Send me login details and I'll have a look
Ron 06 Feb, 2019
I have sent you a PM.. Please see
This topic is locked and no more replies can be posted.