Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Email Obfuscation

Go to End

17 Posts   4115 Views


14 September 2009 at 11:48pm Community Member, 3 Posts

So I am trying to get some Email obfuscation, this is not for forms but to replace mailto: links.
I have tried the hidemailto module with no success so just want a sanity check on my new idea.

Linking to a redirect page?
Set up a redirect page where the redirect url is the mailto link.
Obviously this needs a separate page for each e-mail address, but will this work? If the redirect happens in the php there will be no source code with the address in plain text.
I have tried opening the page in text editors to get the source and they fail.
I know this is obviously not the best way to go about this, but I have no idea what other options I have.



15 September 2009 at 3:41am Community Member, 283 Posts

I'm not sure where you're coming from. Do you want to automatically replace any entered email addresses in the CMS Content Editor with some sort of system? Or do you want to build a system you can statically link to from your pages (ie

I think the simplest thing would be to generate images with the email text in it and just insert those inline when needed. Here is an example to get your running:


15 September 2009 at 4:43am Community Member, 243 Posts

I take it you want something like this: - Script at:

I reckon you have two options:

1. Create a new fieldtype and then either with JS in the CMS or just with the 'onSave' method or some such, store the obfuscated e-mail address.

2. In the content function simply do a preg_replace for all <a> with href="mailto:*" in and parse the e-mail address bit through the obfuscator function.


18 September 2009 at 4:32pm (Last edited: 27 October 2009 2:31pm), Forum Moderator, 921 Posts

Have a look in the Email.php class in your SilverStripe installations.

There's a handy static function in there called "obfuscate". The first parameter to this function is the email address to obfuscate, the second is the method to obfuscate with. 'visible' is the default, but there's also a very handy one called 'direction' that is very good.

Use this for sending obfuscated emails to the templates from your controller. e.g.:

function MyObfuscatedEmail() {
   return Email::obfuscate('', 'direction');

Hope this helps.



27 October 2009 at 10:24am Community Member, 7 Posts

When I add "function MyObfuscatedEmail()" to my Page_Controller and I call $MyObfuscatedEmail in my, Silverstripe only returns "Fatal error: Call to undefined method Email::obsfucate() in Page.php".

So, there are two possibilities:
1. This is not the way to.
2. I haven't understand Silverstripe yet

If its the second possibility: Who can help me...?


27 October 2009 at 12:09pm Community Member, 509 Posts

Looks like a typo, should be:

function MyObfuscatedEmail() {
return Email::obfuscate('', 'direction');


27 October 2009 at 4:03pm Community Member, 7 Posts

I have to apologize...

Thank you.


31 October 2009 at 2:58pm Community Member, 97 Posts


I'm looking for an example of the HTML you'd use when using this function.


Go to Top