Example Number 5.3

Example Name: Email.cfc

Language: CFML

Version: 1.0.0

Code:

<cfcomponent>
  <cffunction name="sendEmail" access="remote">
    <cfargument name="to" required="true" />
    <cfargument name="from" required="true" />
    <cfargument name="subject" required="true" />
    <cfargument name="body" required="true" />
    <cftry>
      <cfmail to = to
       from = from
       subject = subject
     server="mail.yourserver.com">
#body#
      </cfmail>
      <cfcatch type="Any">
        <cfthrow message = "There was an error">
      </cfcatch>
    </cftry>
  </cffunction>
</cfcomponent>

Download code text

Download chapter example files