Jump to content

Obfuscating email addresses in formmail


richrock

Recommended Posts

Hi all,

 

Although this is about formmail (the script), it's really about the implementation of a particular piece of code relating to it.

 

In the form, I have this:

<input type="hidden" name="recipient" value="emailaddress@domain.com" /> 

 

which defines who receives the forms posted to formmail.  This is fine, but the presence of a complete email address has caused a sharp rise in spam being received :(

 

So, for most "<a href="mailto...."'s I use this little piece of javascript:

 

<script language="JavaScript" type="text/javascript">
<!--
var name = "emailaddress";
var domain = "domain.com";

document.write('<a href=\"mailto:' + name + '@' + domain + '?subject=Enquiries\">');
document.write(name + '@' + domain + '</a>');
// -->
</script>

 

And generally it works.

 

But even with my html experience, I'm probably being a complete dummy and can't figure how to merge the two together.  I guess I'm looking for something like:

 

<input type="hidden" name="recipient" value="<script language="JavaScript" type="text/javascript">
<!--
var name = "emailaddress";
var domain = "domain.com";

document.write('<a href=\"mailto:' + name + '@' + domain + '?subject=Enquiries\">');
document.write(name + '@' + domain + '</a>');
// -->
</script>" /> 

 

But it doens't work...  Any ideas, or alternatives to hiding email addresses?

 

TIA

 

Rich

Link to comment
Share on other sites

you really should have the email address as a hidden input, as someone can modify that value and use your script to spam people. instead, define the 'recipient' in the php of the formmail script (i'm pretty sure there is a place already defined)

Link to comment
Share on other sites

Yeah there is a place in the formmail script - it just refers the POST data in this case, the hidden referrer as the email address.

 

I'm looking at a way of stopping this email address being either a: visible in the source code, or b: using a code which can be used to refer to the email address on the server...  hang on, I think that may be it. 

 

I think I'll mark this solved, I'll just need a while to knock up a php script to convert a garbage hidden input into an email address, without it appearing in the source code.  Thanks!

Link to comment
Share on other sites

if there is only one page using the formmail script, just define the email address in the formmail script.

 

if you have multiple pages using the same formmail script, just make a hidden field on each form (call it ref or something) and put it like so:

<input type="hidden" name="ref" value="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" />

then at the top of your formmail script, have a switch statement that assigns the correct variables:

switch($_POST['ref']){
  case '/path/to/page1.php':
    $recipient = 'someone@host.com';
    break;
  case '/path/to/page2.php':
    $recipient = 'someoneelse@host.com';
    break;
  default:
    die("Unknown post");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.