I'm writing a WP Theme where registered users can email post authors sending them en email from the post's page itself.

So I created a contact form in which I get the user and author infos and emails and I put them in hidden input fields to pass them to the php mail function.

Does WordPress have a way to obfuscate the post author's email address, to protect it from scrapers? Is there a better way to implement this functionality, other than outputting the author email address in the form field?


  • I suggest you take a look into the very easy to use wordpress.org/extend/plugins/contact-form-7 instead of reinventing the wheel, although I don't know what you're really aiming for without looking at it. Perhaps you can provide a link?
    – soulseekah
    Commented Oct 18, 2011 at 12:40
  • 1
    As-written, this really isn't a WordPress -related question. Commented Oct 18, 2011 at 12:44
  • @Chip Bennet As there's a template tag/core function for that, it's imo valid and wp related.
    – kaiser
    Commented Oct 18, 2011 at 14:21
  • @kaiser as-written, this question asks about HTML form fields, putting email addresses into hidden form fields, and using the PHP mail function. It could be written in a way that is WordPress related, but it isn't currently. Commented Oct 18, 2011 at 14:30
  • 1
    I've attempted a re-write, to make the question more WordPress-specific. Commented Oct 18, 2011 at 14:44

2 Answers 2


Core function to obfuscate mail addresses:

antispambot( $emailaddy, $mailto );

Second arg is 0 or 1 and optional.

  • Oh! Is this what the OP was asking? Okay, let me attempt an edit to the question to make it more clear. Commented Oct 18, 2011 at 14:40
  • I guess so. I already deleted my answer containing info about the wp_mail() function as I missunderstood it in the first place.
    – kaiser
    Commented Oct 18, 2011 at 15:50
  • If you want to update your answer to discuss wp_mail(), I can delete mine. :) Commented Oct 18, 2011 at 16:09
  • No. It's ok to have different answers to cover the whole topic :)
    – kaiser
    Commented Oct 18, 2011 at 17:09
  • Thanks guys! Question was not clear enought because I didn't know if WP had built-in ways to solve the problem, but antispambot sure will do!
    – teocomi
    Commented Oct 18, 2011 at 17:16

You could alternately use the wp_mail() function to send the commenter's email on form submission. That way, the post author's email address never has to be exposed publicly in the form field to begin with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.