I am using this PHP code to take a users email address from DB and output as l*******@g***.com, for example. This works but email is trying to send to this address as a literal address and always returns an error.. “l*******@g***.com” does not appear to be a valid email address. Verify the address and try again.
Is there an alternate way to hide the email address from Sender. Or can I modify this code so that it is only displayed like this but the real email address remains?
Just need sender to be able to send email, but address hidden from them.
Thank you!
<?php
function hideEmailAddress($email)
{
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
list($first, $last) = explode('@', $email);
$first = str_replace(substr($first, '3'), str_repeat('*', strlen($first)-3), $first);
$last = explode('.', $last);
$last_domain = str_replace(substr($last['0'], '1'), str_repeat('*', strlen($last['0'])-1), $last['0']);
$hideEmailAddress = $first.'@'.$last_domain.'.'.$last['1'];
return $hideEmailAddress;
}
}
$email = "$user->email";
$smail = hideEmailAddress($email);
echo "<a href='mailto:{$smail}?subject=Buongiorno&body=Hello;'>.</a>";
?>