Home > Software design >  Hide or Replace email address mailto: Laravel
Hide or Replace email address mailto: Laravel

Time:12-15

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&amp;body=Hello;'>.</a>";

?>

CodePudding user response:

Not trying to be that person, but this is literally impossible. You need to specify the actual email addresses you want to send

CodePudding user response:

Let's take a simple metaphor and apply it to your request:

I have a poster. I want people who read that poster to send me mail, but not know my address. How can I hide my address, but still let them send mail to it. I tried writing "** P***** R***, I*****", but people couldn't send me mail.

Clearly, this doesn't make much sense: if the people reading the poster can't see the address, how are they going to send anything to it?

So let's tweak it slightly:

I have a poster. I want people who read that poster to send me mail, but not know my personal address. How can I give them somewhere to send me mail without knowing my personal address.

Now some solutions might occur to us:

  • Set up an anonymous mailbox somewhere we can pick up mail from, and put that address on the poster.
  • Make an agreement with a mailing company to forward all mail addressed a certain way to our private address.

This metaphor holds reasonably well for e-mail - you can't send an e-mail without knowing where to send it, but you can:

  • Have a separate e-mail account for particular purposes.
  • Have forwarding rules from one address to another.

Slightly less obvious from the metaphor, and very commonly used, you can use an HTML form as the "forwarding mailbox" - allow the user to enter a message into a form, and have PHP code that takes what they submit, and e-mails it to you.

Note that with any of the above, you will attract spam - people have written software which "crawls" the web looking for anything that looks like an e-mail address or contact form, and tries to send spam to it. That's why you'll generally see a "CAPTCHA" check next to contact forms, to at least make it harder for those bots.

  • Related