The gform_after_email action in Gravity Forms lets you perform actions after an email notification has been sent, either to a user or an admin.
Usage
add_action( 'gform_after_email', 'after_email_function', 10, 12 );
Parameters
$is_success(bool): Indicates if thewp_mailfunction processed the mail request without errors.$to(string): The email address receiving the message.$subject(string): The subject line of the email.$message(string): The body of the email.$headers(array): The headers of the email.$attachments(array): Any attachments in the email.$message_format(string): The email format, either ‘text’ or ‘html’.$from(string): The sender’s email address.$from_name(string): The sender’s name.$bcc(string): The Bcc email address.$reply_to(string): The ‘Reply To’ email address.$entry(Entry Object): The entry being processed, orfalseif not available.
More Information
See Gravity Forms Docs: gform_after_email
This action hook is found in GFCommon::send_email() in common.php. Place this code in the functions.php file of your active theme.
Examples
Retry Sending Email
If the initial email sending attempt fails, this code tries to send it again.
add_action( 'gform_after_email', 'retry_send_email', 10, 7 );
function retry_send_email( $is_success, $to, $subject, $message, $headers, $attachments, $message_format ) {
if ( ! $is_success ) {
// Try sending the email again
$try_again = wp_mail( $to, $subject, $message, $headers, $attachments );
if ( ! $try_again ) {
// Log the failure if the email still can't be sent
}
}
}
Add Note to Entry
This code adds a note to the entry after the email is sent.
add_action( 'gform_after_email', 'add_note_to_entry', 10, 12 );
function add_note_to_entry( $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to, $entry ) {
$current_user = wp_get_current_user();
RGFormsModel::add_note( $entry['id'], $current_user->ID, $current_user->display_name, 'This is a custom note' );
}