Code Snippet

Home » Code Snippets » PHP » Automatic Mailto Links

Automatic Mailto Links

$string = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})','<a href="mailto:\\1">\\1</a>', $text);
echo $string;

Subscribe to The Thread

  1. Keep in mind that the POSIX Regex functions are deprecated in PHP 5.3.0 and removed in PHP 6.

    See http://us2.php.net/manual/en/function.eregi-replace.php

  2. AndiD is right. Use preg_* functions instead of eregi_* functions.

  3. what does this do though? im thinking about making a mail:to link on the footer of my site :

    http://attilahajzer.host-ed.net/

    take a look and see if it’d be worth it.

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~