简体   繁体   English

组装和拆卸电子邮件以防止垃圾邮件

[英]Assemble and disassemble email for spam protection

In our footer we have an email that we are pulling from the database, in php blade it will look like this:在我们的footer我们有email从数据库中提取的email ,在php blade ,它将如下所示:

<a href="mailto:{{ $email }}">{{ $email }}</a>

I need to protect him from spambots.我需要保护他免受垃圾邮件机器人的侵害。

I heard that in php it can be split and then assembled through a javascript , and it will look something like this:我听说在php它可以被拆分然后通过javascript组装,它看起来像这样:

<a href="" data-first="" deta-second="">{{ $email }}</a>

Where data is the parts of the email itself.其中data是电子邮件本身的一部分。 But I didn't understand how to separate it and then collect it.但我不明白如何分离它然后收集它。 Can someone tell me how to do this?有人能告诉我怎么做吗?

Or tell me similar features, how to protect against spambots.或者告诉我类似的功能,如何防止垃圾邮件。

there are nothing to do with PHP with that as PHP is a server-side language.与 PHP 无关,因为 PHP 是一种服务器端语言。

you can do this with Javascript ( will use jquery here to simplify it )你可以用 Javascript 做到这一点(将在这里使用 jquery 来简化它)

this will append the email which is stored in data-mail to the href attribute and once your client clicks it the attribute will be removed again.这会将存储在data-mail的电子邮件附加到href属性,一旦您的客户单击它,该属性将再次被删除。

<a class="email" data-mail="{{ $email }}">{{ $email }}</a>

$('.email').click(function () {
    let t = $(this);

    t.attr('href', 'mailto:' + t.data('mail'));

    setTimeout(() => t.removeAttr('href'), 1);
});

Web scrapers will usually only download plain HTML response.网络爬虫通常只会下载纯 HTML 响应。

In this case you will be protected as long as your code doesn't contain email as plain text and email is put back together onload在这种情况下,只要您的代码不包含纯文本形式的电子邮件,并且电子邮件在onload重新组合在一起,您就会受到保护

Some might even execute JS when scraping your page.有些甚至可能在抓取页面时执行 JS。

To avoid this you can require user to press something to put email together.为避免这种情况,您可以要求用户按一些东西将电子邮件放在一起。 I made a quick example:我做了一个简单的例子:

 function showEmail (element) { const infoData = document.querySelector('[data-target="'+element.id+'"]').dataset; const mail = infoData.p1 + '@' + infoData.p2 + "." + infoData.p3; element.href = "mailto:" + mail; element.text = mail; }
 <a href="" id="mailOutput1" onclick="showEmail(this)">Send Email</a> <!--p1, p2, p3 are filled in PHP --> <span data-target="mailOutput1" data-p1="john.doe" data-p2="example" data-p3="com"></span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM