<?php
/**
* Encodes email addresses in their respective ASCII values to prevent from spam robot harvesting
*
* Creates a mailto: link for the given email address encoded in ASCII
* All known Browsers can display this without problems, but spam harvest robots looking for "@"
* will stay unsuccessful. Whereas this class can not guarantee 100% protection, it provides
* a good solution with no disantvantages for the reader, no Javascript is needed and the mailto:
* is operational as well as copy/paste within the browser
* Optional link text can be given, CSS class and Parameters for the Mailto: link
* such as subject or mail text as associative array ("subject"=>"Mail from my website", "body"=>"Hi! I am sending You this email because I'm bored")
*
* Since the object overhead for only one function is unnecessary, You can just use the mailto_encode method
* as a standalone function
*
* @param String [$sMail] email address
* @param String [$sText] link text (optional)
* @param String [$sClass] CSS class (optional)
* @param Array [$aParams] parameters for subject, mail text etc. (optional)
* @return String The encoder email adress complete with <a href="Mailto: ">
* @author Konstantinos Dafalias <hide@address.com>
* @version 1.0 date
*/
class cMailto_encoder
{
function cMailto_encoder()
{
# Really nothing to do here
}
function mailto_encode($sMail, $sText="", $sClass="", $aParams=Array())
{
$sEncmail ="";
for($i=0; $i<strlen($sMail); $i++)
{
$sEncmail .= "&#".ord(substr($sMail,$i,1));;
}
# If no link text, the email adress is used as text
if(!$sText) $sText = $sEncmail;
# "Mailto: " is added to link
$sEncmail = "Mailto: ".$sEncmail;
$sParams = "";
foreach($aParams as $sKey=>$sValue)
{
if($sParams) $sParams .= "&$sKey=".rawurlencode($sValue);
else $sParams = "?$sKey=".rawurlencode($sValue);
}
return "<a class='$sClass' href='$sEncmail$sParams'>$sText</a>";
}
}
?>