Encode Your Email Addresses in ExpressionEngine

by Jonathan Longnecker

So here’s a quick tip for you ExpressionEngine users. EE will automatically encode any email addresses that are generated by itself. For example, when you leave a comment on this blog and put in your email address, EE will turn it into a mess of javascript nonsense in the code so that those nasty spiders don’t pick up your email and send you dirty emails.

Sometimes you’ve got to manually encode it, though and that’s where this quick tutorial comes in.

Ready? Here we go:

{encode="bob@bobby.com" title="Email Me!"}

Obviously, the encode property is your email and the title is whatever you want. The cool thing is that even if you put your email address in the title, it still gets encoded so the spiders can’t see it. Using the aforementioned block of code creates a mailto: link so you actually save yourself some time writing code! Did I mention I love ExpressionEngine?

February 12, 2008

Tutorials, ExpressionEngine

Comments

  1. Very cool. Thanks!

  2. I have wanted one of these forever! THANKS for the great work

  3. thx for sharing

  4. I search the web for web sites and blogs with good to great content and you’re site by far has proven to be great reading, so please don’t stop you’re doing great.

  5. Awesome!  Quick question:  I have a weblog that has a field for someone’s name and another field for his/her email address.  I’m trying to do two things:

    1) Have the person’s name show and be linked to the person’s email address if the person has included his/her email.
    2) Have that link be encoded. 

    Do you know how I’d do that?  Thanks!!

  6. Hey Stan, I’m not sure exactly what you mean. If you’re talking about leaving a comment and putting the name/email address in EE takes care of the encoding automatically. But if your name and address are custom weblog fields and you want that info to pull on your page you would just use the short name of the custom fields.

    For example: {encode=”{custom_email}” title=”{custom_name}”}.

    Of course that would have to be wrapped in your weblog tags, but you get the idea

  7. hey! Nice tip! I just tried to embed an email within a body of text. Unfortunately, in IE6 and IE7, there’s no “space” between the linked word and the next word. Any thoughts on how to prevent this, or input a hard-coded space? Thanks for the great blog!

  8. @Richard - Hmm I’ve never had that problem. As long as there’s space after the tag it should be fine. Or you could try putting it in the title before the closing quotation mark.

  9. @Jonathan - thanks for the response! There actually is a space, and Mozilla reads it, but IE doesn’t. So IE butts the next word up against the linked word.

    I’ve come up with a workaround, and that is to hardcode a “ ” character into the EE entry. I’m weary of doing it, since the client will look at it and flip out at the ‘crazy internet code’, especially since editing is supposed to make things easier for him.

    Let me know if you come up with a solution!

  10. I actually have the opposite problem.  When IE7 or 8 attempt to display a page containing an EE encoded email address they barf and refuse to display the page.  I want to force EE to just present the html as I write it without doing any fancy encoding on it.  Any ideas how I can do that?

    Ian

  11. @Ian I use the email encode all the time in IE and have never had any issues so there’s probably something else going on. Of course I’m not really sure how you’re entering it. Is it in a template? In a field for a new entry? If it’s in an entry it will encode on the fly, just put the email address in. The above code is only for manual encoding in a template.

  12. Awesome! Just what I needed.

  13. Hi guys, I’m wrapping up my first EE project and I’m looking to add an encode tag to a vCard with microformats. The problem is I can’t find a way to parse the encoded e-mail with the class=“email” I need to make the vCard work…

    Any ideas?

    Thanks for sharing with the newbies!

  14. @Santiago, just put the class on whatever you’re wrapping the email address in. So if it’s in a list with the phone and address; add the class to the <li>. Same if it’s in it’s own tag. Otherwise just use a <span>.

  15. I just learn from the hCard specs that I can use whatever tag I want, even if the email address isn’t a link.  Until yesterday I thought I needed to add the email class directly on the anchor tag to build it right.

    Thanks for the tip!

  16. Is there an option to include a subject line?

  17. @Todd, check the EE docs: http://tinyurl.com/y9h5jfu

  18. Have you experienced an issue with the code EE generates for encoding email addresses in IE8?  We’ve recently experienced an issue where IE8 just stops parsing the HTML once it encounters an email address encoded by EE.

  19. @Terry I have not. I did a quick check in sites we’ve used it on in IE8 and they seem to be fine. Might want to check if you have “Turn urls and emails into links automatically” in your weblog settings. That can cause some conflicts if you’re trying to do it manually and run it through a weblog.

  20. I made sure that setting was turned off; we’re also calling it from a static template.
    It’s just IE8 is chocking on the code, all other browsers are fine with it.

  21. @Terry Very strange; I can’t seem to replicate anything like that. I would make sure you try it in a blank template, and if it still doesn’t work submit a ticket to EE. Might be a bug with your particular version or something.

  22. I was having a similar issue with IE7 not liking the email encoding in EE2. Fixed it by disabling “Automatically turn URLs and Email address into links” setting. That setting is a little buried - goto Admin->Channels and then “Edit Preferences” next to the channel your email address is in. The setting is under “Channel Posting Preferences”. Hope this helps someone!

  23. The blog is cool

  24. Amazing!!!

Behold our Amazing Portfolio

Check it Out