Please, don't just put plain raw emails on your web pages. Bots are going to scrape your pages and fill all of our inboxes with spam emails.
Obfuscate emails and strings in PHP and Laravel to keep those nasty bots away from finding your email or worse, your users' emails.
This package uses different strategies to obfuscate clickable and non-clickable emails, so you can choose what suits your needs best.
You can install the package via composer:
composer require mokhosh/muddle
In Laravel Projects:
{{-- instead of handing your emails to spammers like this: --}}
<a href="mailto:{{ $user->email }}">{{ $user->name }}</a>
{{-- do this: --}}
<x-muddle-link :email="$user->email" :title="$user->name" />
{{-- and we will confuscate the email in random ways to make it impossible for bots to steal your emails --}}
{{-- default strategy components based on config --}}
<x-muddle-link email="[email protected]" title="email" /> {{-- muddled email link --}}
<x-muddle-text email="[email protected]" /> {{-- muddled email text --}}
{{-- specific link strategy components --}}
<x-muddle-random email="[email protected]" title="email" /> {{-- picks a random strategy each time --}}
<x-muddle-append email="[email protected]" title="email" />
<x-muddle-concatenation email="[email protected]" title="email" />
<x-muddle-encrypt email="[email protected]" title="email" />
<x-muddle-entities email="[email protected]" title="email" />
<x-muddle-hex email="[email protected]" title="email" />
<x-muddle-rotate email="[email protected]" title="email" />
{{-- specific text strategy components --}}
<x-muddle-text-random email="[email protected]" /> {{-- picks a random strategy each time --}}
<x-muddle-text-append email="[email protected]" />
<x-muddle-text-concatenation email="[email protected]" />
<x-muddle-text-display-none email="[email protected]" />
<x-muddle-text-encrypt email="[email protected]" />
<x-muddle-text-entities email="[email protected]" />
<x-muddle-text-hex email="[email protected]" />
<x-muddle-text-rotate email="[email protected]" />
use Mokhosh\Muddle\Facades\Muddle;
use Mokhosh\Muddle\Strategies\Text;
use Mokhosh\Muddle\Strategies\Link;
// default strategy
Muddle::text('[email protected]');
Muddle::link('[email protected]');
// specific strategy
Muddle::strategy(text: new Text\Encrypt)->text('[email protected]')
Muddle::strategy(link: new Link\Encrypt)->link('[email protected]');
In plain PHP Projects:
use Mokhosh\Muddle\Muddle;
use Mokhosh\Muddle\Strategies\Text;
use Mokhosh\Muddle\Strategies\Link;
$muddle = new Muddle(
text: new Text\Random,
link: new Link\Random,
);
$muddle->link('[email protected]');
You can publish the config file with:
php artisan vendor:publish --tag="muddle-config"
This is the contents of the published config file:
return [
/*
|--------------------------------------------------------------------------
| Default Strategy
|--------------------------------------------------------------------------
|
| Set default strategies for obfuscating text and email links
|
*/
'strategy' => [
'text' => \Mokhosh\Muddle\Strategies\Text\Random::class,
'link' => \Mokhosh\Muddle\Strategies\Link\Random::class,
],
];
composer test
- Add Dusk tests
- Make loading components dynamic
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
- Mo Khosh
- Joe Tannenbaum for the inspiration.
- Spencer Mortensen for the information.
The MIT License (MIT). Please see License File for more information.