Reply Directly to People Who Fill In Gravity Forms
Sets the Reply-To of Gravity Forms admin notifications to the email address the visitor entered, so hitting Reply answers them instead of your own site.
Opens WPIDE on
Code
add_filter( 'gform_notification', function ( $notification, $form, $entry ) {
if ( '' !== trim( (string) rgar( $notification, 'replyTo' ) ) ) {
return $notification;
}
foreach ( $form['fields'] as $field ) {
if ( 'email' === $field->type ) {
$email = sanitize_email( (string) rgar( $entry, (string) $field->id ) );
if ( is_email( $email ) ) {
$notification['replyTo'] = $email;
}
break;
}
}
return $notification;
}, 10, 3 );
Notes
Notifications that already have a Reply-To keep it; the first email field in the form is used.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.