Replacing 2000 mailto links

I’ve taken over a site that gives viewers the ability to email those on it - each is via a simple mailto: link. With about 2000, and growing, mailto links to replace I’m looking for ideas as to an easy to implement and easy for me to understand solution.

All pages run as shtml and changing all of the includes to php is not an option. I’m pretty sure though that you can stick some php code into an shtml page to call an external page.

The site is broken down into geographical locations so if easier the solution could be several smaller systems. All contact would be via identical forms.

What I want is for viewers to click a link in the web page, be tahen to a form that identifies the recipients business name, they complete the form, and details are sent to recipient.

I’ve hit a brick wall with the way forward so as always any help from you would be appreciated.


Given you only have the target users email address, will you be using this to identify the recipient in some way?

You could replace all instances of to message.php? using whatever method you feel comfortable with.


Sorry, not sure what you are saying. How is that different / better than what is n place now?



The users clicks the href, message.php?, which takes them to a PHP script. This script uses the supplied email address to lookup the business to which it relates and generates the form you desire.


Anthony’s suggestion gives you the ability to use the email address in a form or query on another page rather than the users native email client such as outlook.

You can then run any verification or spam block before sending the email using PHP’s own mail() function.

Off Topic:

Thanks for talking plain English for me Mike! :slight_smile:

That makes sense, thank you. What I really want to achieve though is to remove all email address info from within the web web page coding if possible.

Sorry that I didn’t make that clearer.


What would you use to identify the recipients if not their email address?

I am sorry, I may of completely miss-understood what you are trying to do. However in regards to not displaying the email addresses in the code at all I may have a solution.

Providing you have access to a database (or you could use a flat file to store the information in, with this many email addresses though I am not 100% certain if this is a good idea) you could link up an ID with the email address, and then provide a link to message.php?recipient=5

From here check from your database to see which email address belongs to the recipient with an id of 5, then open a form to send an email to this user from the server (using php’s mail() function).

Or have I completely got the wrong end of the stick? lol

I can break the email addresses down into geographical locations so I could identify the recipients as ayr1, ayr2, ayr3 etc on the web pages and have them in groups per location.

That would allow more expansion in several groups rather than one big one perhaps.

Does that sound possible?


Iterate through all the files you need to, obtain the contents, find the email addresses, perform a lookup based on the email address then replace the email address with a unique identifier.

Something like…

foreach($file in $folder){
  $contents = file_get_contents($file);
  $contents = replace_links($contents);
  file_put_contents($file, $contents);

Which roughly translated will leave you with a toolkit similar to…

function get_id_for_email($email){
  $storage = array(
    1 => '',
    2 => ''
  return array_search($email, $storage);

function get_message_string($email){
  return sprintf(

function callback($match){
  if(true === isset($match[1])){
    return get_message_string($match[1]);
  return $match;

function replace_mailto($string){
  return preg_replace_callback(

$string = '<a href="">contact</a><a href="">contact</a>';

echo replace_mailto($string);

#<a href="message.php?id=2">contact</a><a href="message.php?id=1">contact</a>


In the function get_id_for_email, you would probably perform a database lookup of some sort.

Can you see how we transformed $string ?


Many thanks for that, something to study over the weekend !