<p>It might be that you're trying to parse the variables within quotes <code>"</code> as you set <code>email</code> so you're actually encoding <code>{{ emailContact.emailField }}</code> as a string, not the value it represents. Something like this should work:</p>

<pre><code>{% set email = "&lt;a href='mailto:" ~ emailContact.emailField ~ "'&gt;" ~ emailContact.emailField ~ "&lt;/a&gt;" %}

{{ email|rot13 }}
</code></pre>

CC BY-SA 3.0
2016-12-05T12:48:11.520Z
2016-12-05T12:48:11.520Z
Alec Ritson
<p>There is also this <a href="https://github.com/70kft/craft-emailobfuscate" rel="nofollow noreferrer">EmailObfuscate plugin for Craft CMS</a> which seems to add obfuscation via filter on strings.</p>

<pre><code>{{ entry.body|emailObfuscate }}
</code></pre>

CC BY-SA 3.0
2016-12-06T10:51:07.783Z
2016-12-06T10:51:07.783Z
KSPR
<p>If you're using the <a href="https://github.com/nystudio107/seomatic" rel="nofollow noreferrer">SEOmatic</a> plugin, it exposes an <code>encodeEmailAddress()</code> function that you can use in your templates:</p>

<p><a href="https://github.com/nystudio107/seomatic/wiki/15.-Utility-Filters-&amp;-Functions#encodeemailaddress" rel="nofollow noreferrer">https://github.com/nystudio107/seomatic/wiki/15.-Utility-Filters-&amp;-Functions#encodeemailaddress</a></p>

CC BY-SA 3.0
2016-12-06T09:28:51.720Z
2016-12-06T09:28:51.720Z
andrew.welch
<p>Is there a way to obfuscate an email address link that's generated by a global variable? I tried using Sprout's <a href="https://sprout.barrelstrengthdesign.com/craft-plugins/encode-email/" rel="nofollow noreferrer">Encode Email</a>, but it doesn't seem to work with an email address I've generated by a global variable. Specifically, the global variable doesn't work within an anchor tag. For example, the following doesn't work with Sprout's Encode Email:</p>

<pre><code>{% set email = "&lt;a href='mailto:{{ emailContact.emailField }}'&gt;{{ emailContact.emailField }}&lt;/a&gt;" %}
{{ email | rot13 }}
</code></pre>

<p>In the code above, "emailContact" is the global set and "emailField" is the associated handle for the actual email address.</p>

<p>It'd be great to figure this one out, especially because it seems a lot of folks would want to use a global variable for a contact email address. Thanks!</p>

CC BY-SA 3.0
2016-12-05T06:51:24.543Z
What does the filter output? Also do you have dev mode enabled?
Fyrebase
<craft3><plugin-sproutemail>
Obfuscating email set by global variable
# Obfuscating email set by global variable

(Asked by: username_0 on 2016-12-05)

Is there a way to obfuscate an email address link that's generated by a global variable? I tried using Sprout's Encode Email, but it doesn't seem to work with an email address I've generated by a global variable. Specifically, the global variable doesn't work within an anchor tag. For example, the following doesn't work with Sprout's Encode Email:
{% set email = "{{ emailContact.emailField }}" %}
{{ email | rot13 }}

In the code above, "emailContact" is the global set and "emailField" is the associated handle for the actual email address.
It'd be great to figure this one out, especially because it seems a lot of folks would want to use a global variable for a contact email address. Thanks!

**Tags:** craft3, plugin-sproutemail

> **Comments:**
> **username_1**: What does the filter output? Also do you have dev mode enabled?  

---

## 3 answers

### Answer by username_2 on 2016-12-05. Score: 2

It might be that you're trying to parse the variables within quotes " as you set email so you're actually encoding {{ emailContact.emailField }} as a string, not the value it represents. Something like this should work:
{% set email = "" ~ emailContact.emailField ~ "" %}

{{ email|rot13 }}


---

### Answer by username_3 on 2016-12-06. Score: 1

There is also this EmailObfuscate plugin for Craft CMS which seems to add obfuscation via filter on strings.
{{ entry.body|emailObfuscate }}


---

### Answer by username_4 on 2016-12-06. Score: 1

If you're using the [SEOmatic](https://github.com/nystudio107/seomatic) plugin, it exposes an `encodeEmailAddress()` function that you can use in your templates:

<https://github.com/nystudio107/seomatic/wiki/15.-Utility-Filters-&-Functions#encodeemailaddress>


---

