Skip to content

Instantly share code, notes, and snippets.

@KZeni
Created September 27, 2012 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KZeni/3795580 to your computer and use it in GitHub Desktop.
Save KZeni/3795580 to your computer and use it in GitHub Desktop.
Standalone / On-demand MailHide Function
// On-demand MailHide function (give it a raw email & it returns the raw MailHide url)
// *Useful when added to a WordPress theme's functions.php file if you need to mailhide an email anywhere
// *Usage: <a href="<?php echo mailhide_this('kurt@kzeni.com'); ?>" target="_blank" title="Reveal email address">Send me an email</a>
function mailhide_this($email){
$pubkey = '01aIqfsfCm4RVQsVt7lx95tA==';
$privkey = '228ff0e136ae39a0c7bc22ab595667b9';
$ky = pack('H*', $privkey);
$mode = MCRYPT_MODE_CBC;
$enc = MCRYPT_RIJNDAEL_128;
$block_size = 16;
$numpad = $block_size-(strlen($email)%$block_size);
$email = str_pad($email, strlen($email)+$numpad, chr($numpad));
$cryptmail = mcrypt_encrypt($enc, $ky, $email, $mode, '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0');
$url = 'http://www.google.com/recaptcha/mailhide/d?k='.$pubkey.'&c='.strtr(base64_encode($cryptmail),'+/','-_');
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment