PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Change Notification {admin_email} for From Address

  1. Hi,

    We set up gravity forms for a lot of our clients, however our normal Wordpress install the client usually uses an editor-level account and we handle the admin account. This is to prevent our often very low-tech clients from doing things that will break their site.

    The problem we're having is that although we do try to tell them not to, they're often leaving the From and To fields in their Notifications as {admin_email}. This is a problem because that email address is our email address, not theirs.

    I've looked up the gform_notification hook, and got it working so that if the notification has the text {admin_email} it replaces it with the email address of their account.

    The problem is that this doesn't seem to work on the From field. Is there a way in Gravity Forms to filter the From email address, so that I can replace it with theirs if they haven't manually changed it in the Form Settings?

    I'll be using 1.7 only from now on, so 1.7 filters are fine.

    My code so far (in a custom plugin for stuff like this):

    function gform_notification_email( $notification, $email, $form) {
    	$editor = get_userdata( 2 );
    	$notification = str_replace( '{admin_email}', $editor->user_email, $notification);
    	return $notification;
    add_filter('gform_notification', 'gform_notification_email', 10, 3);


    Jacob @ magicdust

    Edit: Sorry, I should note, that simply doing this:

    $notification['from'] = $editor->user_email;

    Works just fine. However this will overwrite it even if the user changes it. I'd like to preserve whatever's in there, unless it's {admin_email}. Problem is it looks like that even though {admin_email} is what's in the notification settings, it's not actually included in the $notifications array.

    Edit: Ok, It seems just checking if $notification['from] == '' is working. Is there anything wrong with this approach? Are there any other places the admin email address is used I should watch out for?

    I know I've pretty much solved the problem... already, but I'm not super-confident in my solution. So if there's a better way, I'd love to hear it.


    Posted 11 years ago on Wednesday May 1, 2013 | Permalink
  2. This looks like a pretty good solution to your situation. Kudos!

    Posted 11 years ago on Thursday May 2, 2013 | Permalink