<<

Mail

Hands On 22

By Simon Free (Bio)
gist

In this hands on example, you are going to add email functionality to the contact form.

Tags Used: <cfmail>

  1. Open up the /www/contact.cfm file in your code editor.
  2. First we need to create a <cfmail> tag. Locate the line of code which reads 'Form submitted successfully!' on or around line 59.
  3. Before the close tag but still inside the <cfelse> tag, create a <cfmail> tag with the following attributes:
    • from: #form.email#
    • to: me@domain.com
    • subject: Contact Request
    • type: HTML
  4. Once the tag is created, we need to create our email body. After the <cfmail> tag, write the following HTML code:
    <h2>Contact Request</h2>
    <p>
    	From: #form.contactName# (#form.email#)
    </p>	
    <p>
    	#form.message#
    </p>
    
  5. After the closing </p> tag, create a closing </cfmail> tag.
  6. Once the <cfmail> is created, set up the mail server in the ColdFusion Administrator. In your browser, navigate to your ColdFusion Administrator and login. The URL will most likely be http://localhost:8500/CFIDE/administrator/.
  7. Click on the 'Mail' link on the left hand side under 'Server Settings'.
  8. In the 'Mail Server' box, enter 'Localhost' and click 'Submit Changes'. All mail will now go through Localhost, which will allow for viewing in the 'undeliverable' folder.
  9. Open up the /www/contact.cfm page in your browser.
  10. Test the contact form and make sure the email is being sent. Fill out all the form fields and click 'Submit'.
  11. Go back to the Mail page in the ColdFusion Administrator.
  12. Click on the 'View Undeliverable Mail' button, which is under the Mail Spool Settings Heading.
  13. The first email in the list should be the email that was just generated by the Contact form. Click on it, if not already highlighted, and review the email body below the list. You have now successfully sent an email. When you have access to a mail server, you can update the mail settings in the ColdFusion Administrator and it will be sent out to the intended parties.