cfform action to send email when user hits submit

Discussion in 'Programming' started by lespaul00, Dec 11, 2007.

  1. #1
    Is there a simple way to have an email sent to an email address when someone submits a form on my website?

    I'd like an email to be sent to me when someone submits a form. So, upon someone clicking "submit", and action would be to send the email.
     
    lespaul00, Dec 11, 2007 IP
  2. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Do you want the contents of the form to be in the email.

    If so try adding this to your action page:
    
    
    <cfmail to="your email address goes here" from="any address you like" Subject="Order on your website" type="HTML">
    
    <!-- then some text like -->
    "An order has been submitted"
    
    Details:
    <!-- the information from the form you want to see -->
    #form.orderid#
    #form.whatever#
    #form.date#
    
    </cfmail>
    
    <!-- then the rest of your action page will go here-->
    <!-- like if you need to submit the form to your database -->
    
    
    Code (markup):
    <cfmail> wont work if your shared host doesn't have their mail server configured. Chances are they do, but like on my testing server I don't have it configured so I never get the email when I test things at home.
     
    unitedlocalbands, Dec 11, 2007 IP
  3. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    A quick hack is to configure your home computer with fake settings. Emails then go to the cf_root\Mail\Undelivr folder. You can either view them with notepad or use spoolmail

    http://www.coldfusionjedi.com/index.cfm/SpoolMail-CF-Mail-Reader
     
    cfStarlight, Dec 11, 2007 IP
  4. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have my page set up as a cfform... and now it's saying "element DISPLAY_NAME is undefined in cfform"

    <cfform action="submit_recipe.cfm" method="post" name="upload_form" enctype="multipart/form-data" id="upload_form">
    	<p>Your display name:
    	  <cfinput name="DISPLAY_NAME" 
    			type="text" 
    			value="" 
    			size="25" 
    			maxlength="200" 
    			required="true" 
    			message="Please enter a display name!"/>
    
    	</p>	<CFQUERY DATASOURCE="mydatabase" NAME="UPLOAD">
    		   INSERT INTO UPLOAD(DISPLAY_NAME)
    		   VALUES
    		   ( 
    		   <cfqueryparam value="#form.DISPLAY_NAME#" cfsqltype="cf_sql_varchar)
    </CFQUERY>
    
    <cfmail to="me@mysite.com" from="Submitter" Subject="A RECIPE HAS BEEN SUBMITTED" type="HTML">
    
    "A recipe has been submitted."
    
    Details:
    
    #cfform.DISPLAY_NAME#
    
    </cfmail>
    Code (markup):
     
    lespaul00, Dec 17, 2007 IP
  5. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #5
    You could try adding:

    
    [COLOR="Blue"][B]<cfif ISDefined("FORM.DISPLAY_NAME">[/B][/COLOR]
    
    <!--Then your update query goes here -->
    <CFQUERY DATASOURCE="mydatabase" NAME="UPLOAD">
    		   INSERT INTO UPLOAD(DISPLAY_NAME)
    		   VALUES
    		   ( 
    		   <cfqueryparam value="#form.DISPLAY_NAME#" cfsqltype="cf_sql_varchar)
    </CFQUERY>
    
    
    [COLOR="blue"][B]</cfif>[/B][/COLOR]
    
    
    Code (markup):
    Reason being that the user has not submited the form and the variable "form.display_name" is not yet defined. Once they hit submit though, the variable will exist. By adding the if statment, you tell coldfusion to only run the update query if the variable is defined.

    Another thing you could try is:

    
    [COLOR="blue"][B]<cfparam name="form.display_name" default="">[/B][/COLOR]
    
    <cfform action="submit_recipe.cfm" method="post" name="upload_form" enctype="multipart/form-data" id="upload_form">
    	<p>Your display name:
    	  <cfinput name="DISPLAY_NAME" 
    			type="text" 
    			value="" 
    			size="25" 
    			maxlength="200" 
    			required="true" 
    			message="Please enter a display name!"/>
    
    	</p>	<CFQUERY DATASOURCE="mydatabase" NAME="UPLOAD">
    		   INSERT INTO UPLOAD(DISPLAY_NAME)
    		   VALUES
    		   ( 
    		   <cfqueryparam value="#form.DISPLAY_NAME#" cfsqltype="cf_sql_varchar)
    </CFQUERY>
    
    <cfmail to="me@mysite.com" from="Submitter" Subject="A RECIPE HAS BEEN SUBMITTED" type="HTML">
    
    "A recipe has been submitted."
    
    Details:
    
    #cfform.DISPLAY_NAME#
    
    </cfmail>
    
    Code (markup):
    The will create a variable called form.display_name do that the update query is satisfied when the page first loads.
     
    unitedlocalbands, Dec 18, 2007 IP