The gform_pre_send_email filter allows you to modify the email before a notification is sent. You can use it to update the email’s content, format, or even prevent it from being sent.
Usage
add_filter('gform_pre_send_email', 'your_function_name', 10, 4);
Parameters
- $email (array): An array containing email properties such as ‘to’, ‘subject’, ‘message’, ‘headers’, ‘attachments’, and ‘abort_email’.
- $message_format (string): The message format, either ‘html’ or ‘text’.
- $notification (array): An array of properties for the notification object. See Notifications Object for available properties.
- $entry (array): The current Entry Object.
More information
See Gravity Forms Docs: gform_pre_send_email
Examples
Prevent 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; }
Update email properties
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; }
Wrap message in HTML tags
add_filter('gform_pre_send_email', function ($email, $message_format) { if ($message_format != 'html') { return $email; } $email['message'] = '<html>' . $email['message'] . '</html>'; return $email; }, 10, 2);
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);
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);
Place this code in the functions.php
file of your active theme.