Email Action
The Email action sends an email notification whenever a form is submitted. It is the most commonly used action and supports data variables, custom headers, and HTML or plain text content.
Configuration
Configure the Email action in the Actions tab of the form editor. Each form can have multiple Email actions (e.g., one to the admin, one to a department lead).
Fields
| Field | Required | Description |
|---|---|---|
| From | Yes | Sender email address. Defaults to admin_email. |
| To | Yes | Recipient email address. Supports data variables. |
| Subject | No | Email subject line. Defaults to "New submission: {form title}". |
| Message | Yes | Email body. Supports data variables and HTML. |
| Content Type | No | text/plain or text/html (default). |
| Additional Headers | No | One header per line (e.g., Reply-To, CC, BCC). |
Default Settings
When you add a new Email action, Core Forms auto-detects form fields and pre-fills:
From: admin_email
To: admin_email
Subject: New submission: {Form Title}
Message: [all:label]
Headers: Reply-To: [NAME] <[EMAIL]>
Data Variables
Use bracket syntax to insert submission data into any email field:
Field Variables
[field_name] Value of a specific field
[all] All fields as name: value pairs
[all:label] All fields with labels as "Label: value" pairs
System Variables
[CF_FORM_ID] Form post ID
[CF_FORM_TITLE] Form title
[CF_TIMESTAMP] Submission timestamp
[CF_IP_ADDRESS] Submitter's IP address
[CF_USER_AGENT] Submitter's browser user agent
[CF_REFERRER_URL] Page URL where form was submitted
Example: Dynamic Routing
Send to different recipients based on a form field:
To: [department_email]
Subject: New [inquiry_type] inquiry
Message:
Name: [name]
Email: [email]
Department: [department]
Message: [message]
Submitted at [CF_TIMESTAMP] from [CF_IP_ADDRESS]
Example: Reply-To Header
Allow replying directly to the submitter:
Reply-To: [name] <[email]>
Example: CC and BCC
CC: manager@example.com
BCC: archive@example.com
Reply-To: [name] <[email]>
Content Types
HTML Email (default)
When content type is text/html, field values are escaped with esc_html() for safety. Line breaks in [all:label] output render as <br /> tags.
Plain Text Email
When content type is text/plain, HTML tags are stripped. Line breaks render as newlines.
Email Logging
Every email sent through the Email action is logged to the wp_cf_email_logs table with:
- Form ID and submission ID
- To/from addresses
- Subject and message body
- Headers
- Status:
pending,sent, orfailed - Error message (if failed)
View logs in Core Forms > Email Logs in the admin.
// Log entry is created before sending
$log_id = cf_log_email( [
'form_id' => $form->ID,
'submission_id' => $submission->id,
'to_email' => $to,
'from_email' => $from,
'subject' => $subject,
'message' => $message,
'headers' => $headers,
'status' => 'pending',
'action_type' => 'email',
] );
// Status updated after wp_mail() returns
cf_update_email_log_status( $log_id, 'sent' );
// or
cf_update_email_log_status( $log_id, 'failed', $error_message );
Filters
Modify email fields programmatically:
// Change the recipient
add_filter( 'cf_action_email_to', function( $to, $submission ) {
if ( $submission->data['priority'] === 'urgent' ) {
return 'urgent@example.com';
}
return $to;
}, 10, 2 );
// Change the subject
add_filter( 'cf_action_email_subject', function( $subject, $submission ) {
return '[Priority] ' . $subject;
}, 10, 2 );
// Modify the message body
add_filter( 'cf_action_email_message', function( $message, $submission ) {
return $message . "\n\n-- Sent via Core Forms";
}, 10, 2 );
// Modify the from address
add_filter( 'cf_action_email_from', function( $from, $submission ) {
return 'noreply@example.com';
}, 10, 2 );