PHP

Email Address Obfuscator

admin by @admin ADMIN
1d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
Render an email address as HTML that is human-readable but resistant to naive scraping bots. Uses entity encoding and an optional Caesar-style ROT for the mailto link.
PHP
Raw
<?php
function obfuscateEmail(string $email): string {
    $safe = '';
    foreach (str_split($email) as $c) {
        $safe .= rand(0, 1)
            ? '&#' . ord($c) . ';'
            : '&#x' . dechex(ord($c)) . ';';
    }
    return '<a href="mailto:' . $safe . '">' . $safe . '</a>';
}

echo obfuscateEmail('hello@example.com');
// <a href="mailto:&#x68;&#101;...">&#x68;&#101;...</a>
//
// Renders as "hello@example.com" in browsers but most regex-based
// scrapers won't recognize it.
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.