Preset and lock From email field for notifications? [RESOLVED]

Hi All

Has anyone found a method to change the default From email field in Notifications to change it from {admin_email} to a specific email account eg websiteadmin@example.com

We have a specific email address set up with the sender authentication working beautifully but each time one of our users creates a new form and forgets to update the From field their notification email delivery fails or becomes unreliable.

If we could pre-set the default From field and make it uneditable for all forms that would save a lot of support calls and frustration for users.

It seems to be hard coded but maybe this is different in 2.5? Any suggestions much appreciated.

Thanks
Tim

Hi Tim. You could use the gform_pre_send_email filter for that. The code would look like this and apply to all forms on the site, no matter what was set in the notification configuration:

add_filter( 'gform_pre_send_email', 'before_email_sent', 10, 4 );
function before_email_sent( $email, $message_format, $notification, $entry ) {
    GFCommon::log_debug( __METHOD__ . '(): EMAIL BEFORE => ' . print_r( $email, true ) );
    $email['headers']['From'] = 'From: ' . 'Your Name <email@website.com>';
    GFCommon::log_debug( __METHOD__ . '(): EMAIL AFTER => ' . print_r( $email, true ) );
    return $email;
}

Hi Chris

Thanks very much for the speedy response, that is really helpful. We can get that setup and tested on staging right away.

Tim

Perfect - works like a dream.
Thanks again Chris.
Tim

1 Like

There is also https://docs.gravityforms.com/gform_after_save_form/ that lets you customize the default form values including notification.

1 Like

Thanks @JamieO - how did I NOT know about that filter :man_facepalming: