Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

hiding email addresses using php

Featured Replies

Hi guys,

 

I'm working on a website at the mo on which I need to include a contact email address using a Contact Me button. I know there are ways of hiding the address from spam bots using Java but wondered if theres any way using php. I've quickly written this:

 

<?php

 

$mc="@tiscali.";

$ma="pat";

$md="net";

$mb=".james";

 

echo '

 

<p class="emph3"><a onmouseover="window.status=\'mail\'; return true;" onmouseout="window.status=\' \'; return true;"

href="mailto:' . $ma . '' . $mb . '' . $mc . '' . $md . '">Contact Me</a>

</p>';

 

?>

 

but, as I suspected before I'd written it, the full email address still appears on the site when you do "view source" and so I assume that spam bots will be able to see it.

 

Does anyone have any suggestions?

 

Many thanks

 

Rob

Try:

 

<?php

function hideEmail($strText)

{

$strNew = "";

for ($i = 0; $i < strlen($strText); $i++)

{

$strNew .= "" . ord(substr($strText, $i, 1)) . ";";

}

return $strNew;

}

?>

 

Then:

 

<a href="<?php echo hideEmail('mailto:name@domain.com')?>">Contact me</a>

 

Try it - it puts everything into nn notation.

  • Author
Try:

 

<?php

function hideEmail($strText)

{

$strNew = "";

for ($i = 0; $i < strlen($strText); $i++)

{

$strNew .= "" . ord(substr($strText, $i, 1)) . ";";

}

return $strNew;

}

?>

 

Then:

 

<a href="<?php echo hideEmail('mailto:name@domain.com')?>">Contact me</a>

 

Try it - it puts everything into nn notation.

 

:clapping: Thanks ZigPress. That seems to do the trick - at least until the spam bots catch onto the nn notation :rolleyes:

I put mailto emails like below:

 

<script type="text/javascript">
document.write("thisis");
document.write("myemail");
document.write("@hot");
document.write("mail.co");
document.write("m");
</script>

What happens if the user has JavaScript disabled?

 

They go to the contact page and fill out the contact form, lets face it 80% of sites are heavily JS based now, a lot of companies are slowly phasing out the "what if javascript is disabled" motto

Just playing devil's advocate :) I agree that people are probably resigning themselves to the JS requirement, especially with things like Gmail taking over the world.

 

You should still probably see how a screen reader handles it though, especially if it's for a commercial site...

i personally use skidz method, and then if js is disabled it links to the contact form. Very few people other than bots seem to have js disabled.

 

And if they have js disabled, they can just fill out the form, easy peasy.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.