• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

cfmail and attachment path

I'm trying to use CFMAIL to send email from our web application...I need to be able to send an attachment as well. The problem I'm having is when I type in a path (to where the file that I want to attach).

For some reason its not passing the value I put in the form. I'm using <input type="file" name "attach1">
and the form tag looks like <form action="email.cfm?popup=1&action=1" method="post" enctype="multipart/form-data">

in the text box for attachments I type in:
C:\docs\1234.doc

when I do a CFDUMP on form.attach1 it gives me:
D:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp49797.tmp

why would it point to this directory instead of what I typed into the text box?
0
stacey14
Asked:
stacey14
  • 8
  • 6
  • 3
1 Solution
 
bwasyliukCommented:
The <input type="file"... tag (within the browser) is looking for a file on the users computer - not on the server.

The file would normally be saved in your form processing page using a <cffile action="upload"...

then you can use #cffile.serverdirectory# and #cffile.serverFile# to reference the file that now exists on the server.

Once you have sent the file as an attachment, you could then cleanup and delete the file from the server (if you dont need to keep it for anything).

<cffile action="delete"...
0
 
stacey14Author Commented:
I have the <Cffile action=upload> code right below the CFDUMP...I did the dump to see what the form was passing in because I get an error when it hits the CFFILE code because of the garbage the form field is passing in. I'm wondering why the form field isn't returning what I keyed in
0
 
bwasyliukCommented:
can you share the error you are getting?
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
ExpertAdminCommented:
By the time your page posts, the file has already been uploaded and stored in a temporary folder.  Withthe File Input box, you specify the path and the control actually uploads the file and then returns the temporary location of where the file is being stored on the server.

So you would need to attach

D:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp49797.tmp

to your email. CF doesn't care where it originated on the user's machine because it has a copy already uploaded.

M@
0
 
stacey14Author Commented:
the error message I get is:

The form field ""D:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp49804.tmp"" did not contain a file.
0
 
bwasyliukCommented:
Is this error coming from the <cffile tag or from the <cfmail tag?
0
 
stacey14Author Commented:
<cffile>
0
 
bwasyliukCommented:
can you show the cffile code?
0
 
stacey14Author Commented:
<cffile action="upload"
          filefield="#form.attachment1#"
         destination="d:\ProdWebsite\apps\teachcert\gallery\"
         nameconflict="Makeunique">
       
<cfset attachdoc = "d:\ProdWebsite\apps\teachcert\gallery\#file.serverfile#">

<cfmail to="#form.to_email#" from="#form.from_email#" subject="#form.subject#" cc="#form.CC_email#" bcc="#form.bcc_email#">
    <cfsilent>
      <cfmailparam file="#attachdoc#">
       #reply_message#
    </cfsilent>
</cfmail>
0
 
bwasyliukCommented:
I think the issue is with the ## in the filefield="#form.attachment1#" area of the code.

The CF documentation says to make sure you dont use #'s in your filefield attribute.
0
 
stacey14Author Commented:
something else I noticed...instead of the body of the message the email is displaying:



any ideas?
0
 
bwasyliukCommented:
I'm not sure about the <cfsilent... inside a <cfmail body area...  I would try removing that first.
0
 
stacey14Author Commented:
once I removed the <cfsilent> the body message starting showing up but that other garbage is still showing up as well.
0
 
bwasyliukCommented:
Not sure if it is related, but I always specify charset="iso-8859-1" in my cfmail tags.  Also, the carriage returns & whitespace between the end of your <cfmail...> and </cfmail> tags will be included with the message.  You may need to play around with removing blank lines, etc in order to get the message format you want.
0
 
ExpertAdminCommented:
I think that you are passing the binary file content where it is expecting a file name.

Try this:

<cfmail to="#form.to_email#" from="#form.from_email#" subject="#form.subject#" cc="#form.CC_email#" bcc="#form.bcc_email#">
    <cfsilent>
     <cfmailparam file=#attachdoc#>  <!---I left off the quotes here --->
      #reply_message#
    </cfsilent>
</cfmail>

M@
0
 
ExpertAdminCommented:
I am pretty sure that last suggestion would do the trick for them...but a lot of folks participated in this one so I suggest a split.

M@
0
 
bwasyliukCommented:
There were a number of issues going on here that got solved - ExpertAdmin and I did answer each of them, so I would agree with a split.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now