beastbytes/emailobfuscator

Widget to obfuscate email addresses

v1.0.0 2023-06-29 14:43 UTC

This package is auto-updated.

Last update: 2024-04-14 12:34:57 UTC


README

Widget to obfuscate an email address to help prevent harvesting by spam bots.

If JavaScript is disabled on the client, the widget will output either a message or an obfuscated version of the email address.

If JavaScript is enabled the output is replaced with (by default) a mailto link showing (again by default) the email address. The content of the mailto link can be customised.

For license information see the LICENSE file.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist beastbytes/emailobfuscator

or add

"beastbytes/emailobfuscator": "^1.0"

to the require section of your composer.json.

Usage

Use this extension in a view.

To output the default message ("This e-mail address is protected to prevent harvesting by spam-bots")

echo EmailObfuscator::widget([
    'email' => 'my.address@example.com'
]);

Output

JavaScript Disabled

<span id="w0">This e-mail address is protected to prevent harvesting by spam-bots</span>

JavaScript Enabled

<span id="w0"><a href="mailto:my.address@example.com">my.address@example.com</a></span>

To output a different message set content['obfuscated']

echo EmailObfuscator::widget([
    'email' => 'my.address@example.com',
    'content' => ['obfuscated' => 'Enable JavaScript to see the email address']
]);

Output

JavaScript Disabled

<span id="w0">Enable JavaScript to see the email address</span>

JavaScript Enabled

<span id="w0"><a href="mailto:my.address@example.com">my.address@example.com</a></span>

To output an obfuscated version of the email address set the obfuscators: "my dot address at example dot com"

echo EmailObfuscator::widget([
    'email' => 'my.address@example.com',
    'obfuscators' => [' dot ', ' at ']
]);

Output

JavaScript Disabled

<span id="w0">my dot address at example dot com</span>

JavaScript Enabled

<span id="w0"><a href="mailto:my.address@example.com">my.address@example.com</a></span>

To set the content of the mailto link, set content['clear']

echo EmailObfuscator::widget([
    'email' => 'my.address@example.com',
    'content' => ['clear' => 'by email']
]);

Output

JavaScript Disabled

<span id="w0">This e-mail address is protected to prevent harvesting by spam-bots</span>

JavaScript Enabled

<span id="w0"><a href="mailto:my.address@example.com">by email</a></span>