# Cannot replace {admin\_email} merge tag

**URL:** <https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908>\
**Category:** Get Help\
**Tags:** custom, gform\_after\_save\_form, gform\_replace\_merge\_tags, admin\_email, gform\_pre\_replace\_merge\_tags\
**Created:** [February 14, 2022, 5:49pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908 "2022-02-14T17:49:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![FriendlyWP](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/friendlywp/32/4138_2.png) [@FriendlyWP](https://community.gravityforms.com/u/FriendlyWP)\
**Post date:** [February 14, 2022, 5:49pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/1 "2022-02-14T17:49:49Z")

</div>

Hi, I’m trying to write an Add-on that will add a custom ‘admin email’ address which is used for Gravity Forms only, but I’m having trouble replacing the default {admin\_email} merge tag results. I’ve tried using the `gform_replace_merge_tags` filter and the `gform_pre_replace_merge_tags` filter but neither seems to do the trick.

Looking in common.php I can’t find where any filter is actually being called that would allow for this - looks like pulling from WordPress’s default Administrator Email settings is fairly hard-coded. Am I missing something? This functionality is VERY needed and I’m happy to share the add-on with the community if I could get it to work!

Thanks.

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [February 15, 2022, 5:13pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/2 "2022-02-15T17:13:05Z")

</div>

Replacing the default output of a default merge tag is not recommended, instead it would be better to create your own merge tag. That’s the purpose of the gform\_replace\_merge\_tags filter really.

If you really want to alter the output of a default merge tag, you will want to use this other filter: [gform\_merge\_tag\_filter - Gravity Forms Documentation](https://docs.gravityforms.com/gform_merge_tag_filter/)

Using this filter, it’s up to your code to alter the default value or provide a new one.

---

<div class="post-metadata">

**Author:** ![FriendlyWP](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/friendlywp/32/4138_2.png) [@FriendlyWP](https://community.gravityforms.com/u/FriendlyWP)\
**Post date:** [February 15, 2022, 5:47pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/3 "2022-02-15T17:47:03Z")

</div>

I tried that one too, but it didn’t work. In common.php on lines 1233/1234 I see these comments which imply it’s not yet configured:

```auto
// TODO: Deprecate the 'gform_replace_merge_tags' and replace it with a call to the 'gform_merge_tag_filter'|
//$text = apply_filters('gform_merge_tag_filter', $text, false, false, false );|

```

The reason I want to edit the default {admin\_email} merge tag is because it’s set as the default for Admin Notifications on all forms. My users, on dozens of sites, very seldom remember to go in and change those default notifications in any way, so it always uses the default site admin email (mine). I need to be the main site admin so I can remain responsible for plugin updates etc but I don’t want all the contact form stuff. Adding a global custom admin-email option for all GF forms to use seems like an easy solution.

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [February 15, 2022, 9:58pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/4 "2022-02-15T21:58:04Z")

</div>

Hi Michelle. I think I understand the issue: the `{admin_email}` merge tag is used by default as the TO and FROM address for all newly created notifications. You are the website admin, so you are getting unwanted emails from the forms when those emails should be going to (and from?) the site owners’ email addresses. Is that correct?

If you _could_ default to a different merge tag for the TO and FROM for every new form notification, where would that merge tag get its email address from? I assume on dozens of sites that each site might have its own email address that should receive the form notifications?

For example, assuming you could redefine where `{admin_email}` gets its address, where would that come from instead?

---

<div class="post-metadata">

**Author:** ![FriendlyWP](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/friendlywp/32/4138_2.png) [@FriendlyWP](https://community.gravityforms.com/u/FriendlyWP)\
**Post date:** [February 15, 2022, 10:41pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/5 "2022-02-15T22:41:09Z")

</div>

Hi Chris! That’s exactly right.

In the Add-on I’ve been working on, I just added a setting/custom text field to store the alternate GF admin email address. If this could be built into GF core I’d expect that field to be on the main GF Settings page, but I had it in its own tab within the GF settings area.

I haven’t yet addressed the validation rules for the custom field (since I couldn’t get the proof of concept to work) but it would need to be validated as a single email address. If someone left the field empty, it would default to the way things work now, using the original site admin email as defined in Settings \> General.

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [February 16, 2022, 2:51pm UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/6 "2022-02-16T14:51:26Z")

</div>

Michelle, for the use case described I would recommend you one of the following:

a) Set a custom default email address for the notification each time a new form is created. You can do this using the following filter: [gform\_after\_save\_form - Gravity Forms Documentation](https://docs.gravityforms.com/gform_after_save_form/)

Just change this line:

```auto
$notification['to'] = 'name@domain.com';

```

You can find the documentation for the notification object here: [Notifications Object - Gravity Forms Documentation](https://docs.gravityforms.com/notifications-object/)

b) Override the notifications properties on the fly using this other filter: [gform\_notification - Gravity Forms Documentation](https://docs.gravityforms.com/gform_notification/)

---

<div class="post-metadata">

**Author:** ![FriendlyWP](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/friendlywp/32/4138_2.png) [@FriendlyWP](https://community.gravityforms.com/u/FriendlyWP)\
**Post date:** [February 18, 2022, 12:16am UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/7 "2022-02-18T00:16:14Z")

</div>

Thanks Samuel, I’ll do that. I have it working now setting a default ‘to’ and ‘from’ email (separately) via a new global settings tab, and it’s working great.

One more question - is there any built-in GF function for field validation in the settings area? I use the `feedback_callback` and a simple function (below) to validate my fields contain email addresses, but `feedback_callback` doesn’t prevent the form from being submitted nor does it show a textual error message. I do get the red X if someone enters an invalid email, but it’s still saved.

```auto
public function is_valid_setting( $value ) {
    return is_email($value);
}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [March 20, 2022, 12:16am UTC](https://community.gravityforms.com/t/cannot-replace-admin-email-merge-tag/11908/8 "2022-03-20T00:16:16Z")

</div>

Closed on March 20, 2022, 12:16am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
