Email Contact Form

The purpose of this tag is to create a contact form so your users can easily send you an email for various purposes like support, errors, or affection. To show your contact form use this tag pair:

{exp:email:contact_form}

{/exp:email:contact_form}

The contact form is created pretty much like a normal form, only you don't specify the opening and closing form tags; ExpressionEngine takes care of those for you. There are a few variables that are available in order to auto-fill fields in the form, and also a few tag parameters to specify form handling and hidden recipients. Here's an example of how a contact form could be created:

{exp:email:contact_form user_recipients="false" recipients="admin@yoursite.com" charset="utf-8"}

<h2>Support Form</h2>

<p><label for="from">From:</label><br />
<input type="text" id="from" name="from" size="40" maxlength="35" value="{member_email}" /></p>

<p><label for="subject">Subject:</label><br />
<input type="text" id="subject" name="subject" size="40" value="Contact Form" /></p>

<p><label for="message">Message:</label><br />
<textarea id="message" name="message" rows="18" cols="40">Support Email from: {member_name}
Sent at: {current_time format="%Y %m %d"}</textarea></p>

<p><input name="submit" type='submit' value='Submit Form' /></p>

{/exp:email:contact_form}

Parameters

charset=

charset="utf-8"

This allows you to set the character set of the email being sent. Use this if you form's template is using a character set other than iso-8859-1.

recipients=

recipients="admin@example.com"

You may specify hidden recipients for the form. This is who will receive the submitted information. You may specify more than one recipient by separating the email addresses with commas:

recipients="admin@example.com,ceo@example.com,president@example.com"

user_recipients=

user_recipients="true" user_recipients="false"

The user_recipients parameter specifies whether or not the form will accept having the user input the recipients via the 'to' field in the form. If set to true, then you can create a 'to' form field where the user can input the addresses to which the email should be sent.

return=

return="http://www.example.com/index.php"

This parameter lets the admin specify to where the user is directed after the form is submitted. Upon submission, the user is presented with a standard "thank you" message and a link. The return parameter lets the location for the link be specified.

Variables

author_email

{author_email}

If you create a permalink to a page containing the {exp:email:contact_form} tag, then the form allows the use of this variable to put in the email address of the author who wrote the linked entry. This feature allows the creation of a "contact author" page.

author_name

{author_name}

If you create a permalink to a page containing the {exp:email:contact_form} tag, then the form allows the use of this variable to put in the screen name of the author who wrote the linked entry. This feature allows the creation of a "contact author" page.

member_email

{member_email}

If a user is logged in, then it will display their email address as recorded in their member profile.

member_name

{member_name}

If a user is logged in, then it will display their screen name as recorded in their member profile.

Form Fields

from

<input type="text" name="from" size="40" />

Email address of person who is sending the email.

message

<textarea name="message" rows="10" cols="40"></textarea>

Main message of the email. You must include this form field, even if it is just a hidden field.

name

<input type="text" name="name" size="40" />

Name of person who is sending the email.

required

<textarea name="required" rows="5" cols="40" readonly="readonly"></textarea>

This field allows you to have required information that is included at top of each email. Useful for support emails where the information can be readonly or hidden.

You may specify multiple pieces of fields of required data by making the name= attribute an array by using "required[]". For example:

Age: <input name="required[]" size="3" maxlength="3" /><br />
<br />
Bio: <textarea name="required[]" rows="5" cols="40"></textarea>

subject

<input type="text" name="subject" size="40" />

Subject of the email that is being sent. You must include this form field, even if it is just a hidden field.

to

<input type="text" name="to" size="40" />

Email address to which the email is being sent. Multiple email addresses may be specified by separating them with a comma. You must include this form field, even if it is just a hidden field. This data may also be specified with the recipients= parameter of the tag.