0

I'm very new to ColdFusion (this is my second day dealing with it) and I am implementing a simple HTML page. I have a feedback form on this page and when the user hits submit, I want to email the contents of the form to myself. I have to do it using cfmail.

To try it out before I implemented it, I created the following cfmail.cfm file:

<cfmail from="#form.from#" to="myemailaddress" type="html">
    Some text
</cfmail>

and passed the name of the file to the action attribute of my form. Every time I click submit on my form, it just opens the above file.

All the examples I find online pretty much show the same thing, but obviously I'm way off here.

Am I using cfmail in the wrong manner?

Thanks in advance for your help!

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
  • First, you need a subject. That's a required field. Second, what version of CF are you using? – Evik James Jun 01 '12 at 21:17
  • 1
    Do other .cfm pages get their coldfusion code processed? If not, then it sounds like you may have a problem with your installation. How did you install ColdFusion? (or are you using an open-source CFML engine?) – Jordan Jun 01 '12 at 21:46
  • Doh! I missed the `cfmail.cfm` part ;-) – Leigh Jun 01 '12 at 21:52
  • @EvikJames I'm not really sure. It's a project for work. I'll have to check Monday. – gordy_gekko Jun 01 '12 at 21:54
  • @Jordan Yes they do. We use other cfm pages for a lot of stuff, I think. Is the way I'm doing it actually allowed? That is creating a .html page with a form whose action attribute is = to the name of a .cfm file? – gordy_gekko Jun 01 '12 at 21:56
  • @Gordy, yes you can make a cfm page to be the action attribute. – Turnkey Jun 02 '12 at 12:38

2 Answers2

1

Just like Evik said in the comments, add a subject because it is a required field for the cfmail tag.

<cfmail to="#form.mailto#" from="#form.mailFrom#" subject="#form.subject#">
  #form.body#
</cfmail>

Also check the mail settings in the ColdFusion administrator under Setting > Mail. There is also a mail log in the administrator you can check.

I recommend using Adobe online docs for ColdFusion. I referrer to it almost daily, they are great.

Here is a link to the cfmail for CF8 but at the bottom it links to other version.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_m-o_01.html

Brandon
  • 320
  • 1
  • 4
  • 13
  • I got it to work, but how do you return to the page you were on? Ideally, I'd like the to hide the form and display a message that says "Thanks for your feedback." – gordy_gekko Jun 04 '12 at 20:03
  • .... Then have your form post to itself and have your submit button with name="submit" – Brandon Jun 04 '12 at 20:31
  • thanks for your help. Can I put that directly in my html? I'm not sure if this makes a difference, but my form is in my html file. The only thing I put in a cfm file is the tag. This is pretty much where coldfusion confuses me. – gordy_gekko Jun 05 '12 at 00:00
  • Yes, ColdFusion code and html go together but it needs to be a file that will get executed by the ColdFusion interpreter (ie: extension of the file should be .cfm). So you want to add your form html into your cfmail file. You should Google search "ColdFusion Tutorial" for help learning the basics. You can do the cfif in the body of the html code to get it to print the correct section based on the submit button status and not have to touch header/footer of page. – Brandon Jun 05 '12 at 02:39
  • that would be easier, but most of the code for this site was developed all ready by someone else, so I don't want to change the file types of the html files. This creates a problem, because all types of crazy things are happening when I use teh cflocation tag in my cfmail file. – gordy_gekko Jun 05 '12 at 17:06
1

If it's just opening the file and not throwing a ColdFusion error (which it should do without the subject) then you most likely have a problem in your ColdFusion installation or more likely in the setup of your development web server is not handling the cfm scripts (IIS or Apache depending on the platform).

Turnkey
  • 9,266
  • 3
  • 27
  • 36
  • Would this still make sense if other coldfusion scripts ran for the program? – gordy_gekko Jun 02 '12 at 17:10
  • No, that is very weird to see that it doesn't process at all for one page but for others - I haven't seen that happen. Put a "Hello World" type cfm file in that same folder as the email one and confirm that it does work with just a get request. Perhaps it's something to do with the folder not being active for CF if it is a virtual folder. – Turnkey Jun 02 '12 at 22:23
  • I'll try that. Did I use cf in the proper way? That is, putting the form in a normal html file and setting the action attribute to the name of the cfm file? Also, is anything required in the cfm file other than the cfmail tag? – gordy_gekko Jun 04 '12 at 13:59
  • disregard that last comment, I just saw your answer uptop. I tried a helloworld example, and I don't think the coldfusion scripts that I write are running on my computer. It's weird, because the one's that were written by someone else for the website are working. – gordy_gekko Jun 04 '12 at 14:08
  • It seems you are writing them OK I don't think it is affected by white space issues and if it were you'd see a parse error rather than downloading the source file. I would double-check the installation. – Turnkey Jun 04 '12 at 14:32