Use this function to hide an e-mail address from spam-bots on your website. This custom PHP function will convert the e-mail address into Unicode values and will add the html tag and optional extra e-mail info like subject and body text. Test the demo page for an example.
function hide_mailto($mail, $label, $subject = "", $body = "") {
$chars = preg_split("//", $mail, -1, PREG_SPLIT_NO_EMPTY);
$new_mail = "<a href=\"mailto:";
foreach ($chars as $val) {
$new_mail .= "&#".ord($val).";";
}
$new_mail .= ($subject != "" && $body != "") ? "?subject=".$subject."&body=".$body : "";
$new_mail .= "\">".$label."";
return $new_mail;
}
Example usage:
echo hide_mailto('info@domain.com', 'Open a link', 'The email subject', 'The mail message...');