You are viewing documentation for v1.1.x. Change

sendEmail()

Description

Sends an email using a template and an optional layout to wrap it in. Besides the Wheels-specific arguments documented here, you can also pass in any argument that is accepted by the cfmail tag as well as your own arguments to be used by the view.

Function Syntax

sendEmail([ template, from, to, subject, layout, file, detectMultipart ])

Parameters

Parameter Type Required Default Description
template string No The path to the email template or two paths if you want to send a multipart email. if the detectMultipart argument is false, the template for the text version should be the first one in the list. This argument is also aliased as templates.
from string Yes Email address to send from.
to string Yes List of email addresses to send the email to.
subject string Yes The subject line of the email.
layout any No false Layout(s) to wrap the email template in. This argument is also aliased as layouts.
file string No A list of the names of the files to attach to the email. This will reference files stored in the files folder (or a path relative to it). This argument is also aliased as files.
detectMultipart boolean No true When set to true and multiple values are provided for the template argument, Wheels will detect which of the templates is text and which one is HTML (by counting the < characters).

Examples

<!--- Get a member and send a welcome email, passing in a few custom variables to the template --->
<cfset newMember = model("member").findByKey(params.member.id)>
<cfset sendEmail(
    to=newMember.email,
    template="myemailtemplate",
    subject="Thank You for Becoming a Member",
    recipientName=newMember.name,
    startDate=newMember.startDate
)
>