Hello, I tried to create a contact form, using email to send, and I have some issues and questions: 1. I like to have a message "Your form has been sent", but it shows the blank after user submited the form. 2. If user enter her email address, this form will send to her email address and me, but it does not send to her email address. Can anyone please take a look at my code below? Why I don't get the output (result) I like to have? Thanks very much. Jenny. <cfif IsDefined("form.Subject")> <cfprocessingdirective suppresswhitespace="no"> <cfmail subject="#form.Subject#" from="#form.From#" to="test@test.com" > This is a message from that form... #form.Message# </cfmail> </cfprocessingdirective> <cfelse> <cfform action="#CGI.SCRIPT_NAME#" method="post" name="frmName"> name <cfinput type="text" name="Name" size="20"><br /> email <cfinput type="text" name="Email" size="20"><br /> Subject <cfinput type="text" name="Subject" size="20"><br /> Message <textarea name="Message" cols="30" rows="3" ></textarea><br /> <input type="submit" value="Submit it" /> </cfform> <cfif isDefined("FORM.Name")> <cfmail subject="#form.Subject#" from="#form.From#" to="#Email#" > </cfif> <cfif isDefined("FORM.Submit")> <p>Your message has been sent</p> <cfelse> <cflocation addtoken="no" url="survey2.cfm"> </cfif>
form.from doesn't exist in the code you've posted, so Coldfusion should be throwing an error. Also, your second <cfmail> tag doesn't have an ending tag, which should also throw an error. It looks like you've pasted multiple code samples together, because a lot of your code is redundant or broken - is that the case? Very generally, if any one form variable is defined, then the other variables are defined, too. So, you've got all these <cfif isDefined("form.something")>'s, but in your script you've got (pending bots or spammers) they will all always be defined. Here's a very messy example that should probably work (I make no claims to it's performance - I just threw it together.): ----------- <cfif structKeyExists(form, "submit")> <cfprocessingdirective suppresswhitespace="no"> <!--- send email to test@test.com ---> <cfmail subject="#form.Subject#" from="#form.From#" to="test@test.com" >This is a message from that form... #form.Message# </cfmail> <!--- send an email to the person who submitted the form ---> <cfmail subject="#form.Subject#" from="#form.From#" to="#Email#" > </cfmail> </cfprocessingdirective> <!--- output a friendly thank-you ---> Thank you for submitting this form! It's been mailed to very important people, and yourself so that you can be helped in some manner, if it's required. <cfelse> <cfform action="#CGI.SCRIPT_NAME#" method="post" name="frmName"> name <cfinput type="text" name="Name" size="20"><br /> email <cfinput type="text" name="Email" size="20"><br /> Subject <cfinput type="text" name="Subject" size="20"><br /> Message <textarea name="Message" cols="30" rows="3" ></textarea><br /> <input type="submit" value="Submit it" /> </cfform> Code (markup): ---- That being said, you *really* should put some form of input validation on this, because if you don't, your CF server will have a fit when your users start submitting pages that don't have valid email addresses. CF will allow the pages to be submitted, but your mail log and mail queue will start getting filled with bad messages. It's also worth noting that cfform, cfinput, and stuff like cfinsert and cfupdate are really old and probably should be shot, buried, and forgotten for the good of all CF programmers everywhere.