Hi all,
I wanted to receive an email notification even the submission was failed or contains an error validation. The email notifications should contain all the data entered in the input fields. I used “gform_after_submission” hook to meet the requirements. However, I don’t know why it is not working. Please see my code below. Thank you in advance!
==========
add_action( ‘gform_after_submission’, ‘custom_send_email_notification’, 10, 2 );
function custom_send_email_notification( $entry, $form ) {
// Specify the form ID you want to include
$target_form_id = 123; // Replace 123 with your actual form ID
// Check if the submitted form matches the target form
if ( $form['id'] == $target_form_id ) {
// You can customize the email recipients, subject, etc. here
$to = 'recipient@example.com';
$subject = 'Form Submission';
// Build email message with all input fields
$message = '';
foreach ( $form['fields'] as $field ) {
$value = rgar( $entry, $field->id );
$label = $field->label;
$message .= "$label: $value\n";
}
// Send email
wp_mail( $to, $subject, $message );
}
}