gform_pre_send_email

gform_pre_send_email

DescriptionUsageParametersExamples1. Abort emails.2. Update email meta.3. Wrap message in HTML tags.4. Copy To to Bcc.5. Change default font sizes for a notification using {all_fields}PlacementSource Code

Description
Use this filter to modify the email before a notification has been sent. You may also use this to prevent an email from being sent.
Usage
add_filter( 'gform_pre_send_email', 'your_function_name', 10, 4 );

Parameters

$email array
Array
(
[to] => [email protected]
[subject] => New submission from A
[message] => This is the email body.
[headers] => Array
(
[From] => From: "[email protected]"
[Content-type] => Content-type: text/html; charset=UTF-8
)

[attachments] => Array
(
)

[abort_email] => FALSE
)

$message_format string
The message format, html or text.

$notification array
An array of properties which make up a notification object. See Notifications Object for possible properties. Available from 1.9.15.6.

$entry array
The current Entry Object. Available from 2.2.3.8.

Examples
1. Abort emails.
This example prevents the email from being sent.
add_filter( 'gform_pre_send_email', 'before_email' );
function before_email( $email ) {
//cancel sending emails
$email['abort_email'] = true;
return $email;
}

2. Update email meta.
This example updates the to address, subject, and message.
add_filter( 'gform_pre_send_email', 'before_email' );
function before_email( $email ) {
$email['to'] = '[email protected]';
$email['message'] = 'This is my new message.';
$email['subject'] = 'This is a new subject.';
return $email;
}

3. Wrap message in HTML tags.
add_filter( 'gform_pre_send_email', function ( $email, $message_format ) {
if ( $message_format != 'html' ) {
return $email;
}

$email['message'] = '' . $email['message'] . '';

return $email;
}, 10, 2 );

4. Copy To to Bcc.
add_filter( 'gform_pre_send_email', function ( $email, $message_format, $notification ) {
if ( $notification['name'] != 'User Email' ) {
return $email;
}

$email['headers']['Bcc'] = 'Bcc: ' . $email['to'];
$email['to'] = '[email protected]';

return $email;
}, 10, 3 );

5. Change default font sizes for a notification using {all_fields}
add_filter( 'gform_pre_send_email', function ( $email, $message_format ) {
if ( $message_format != 'html' ) {
return $email;
}

// Change default 12px to 18px
$email['message'] = str_replace( 'font-size:12px', 'font-size:18px', $email['message'] );

// Change default 14px to 20px
$email['message'] = str_replace( 'font-size:14px', 'font-size:20px', $email['message'] );

return $email;
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This action hook is located in GFCommonn::send_email() in common.php

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注