简体   繁体   English

在javascript中发送有关控制台错误的电子邮件

[英]Sending Emails on console errors in javascript

Research I have done for this question and links: 我针对这个问题和链接进行了研究:

How do you send console messages and errors to alert? 您如何发送控制台消息和错误以发出警报?

jQuery AJAX form using mail() PHP script sends email, but POST data from HTML form is undefined 使用mail()PHP脚本的jQuery AJAX表单发送电子邮件,但HTML表单的POST数据未定义

The code example: 代码示例:

function handleError(evt) {
  if (evt.message) { // Chrome sometimes provides this
 $.ajax({
            type: "POST",
            url: "email.php",
            data: evt.message,
            success: function(){
            $('.success').fadeIn(1000);
            }
        });
  } else {
    $.ajax({
            type: "POST",
            url: "email.php",
            data: evt.type,
            success: function(){
            $('.success').fadeIn(1000);
            }
        });
  }
}

Question) What type of validation is required in "email.php" to be sure that the emails aren't malicious (to the extent that this is possible) IE: is there a vulnerability that you are exposing yourself to with this function. 问题)在“ email.php”中需要进行哪种类型的验证,以确保电子邮件不是恶意的(在可能的范围内)IE:使用此功能是否会使您暴露于漏洞。 If there is a built in mechanism for changing the location of error logs in javascript, that too would answer this question. 如果有内置机制可以更改javascript中错误日志的位置,那也将回答此问题。

I assume you're sending it to a known email address so checking the email isn't required? 我认为您是将其发送到已知的电子邮件地址,因此不需要检查电子邮件吗?

filter_var($email, FILTER_VALIDATE_EMAIL)

Then clean the data to be sent from anything that makes your email stop from functioning properly. 然后清除所有使电子邮件无法正常运行的内容中要发送的数据。

function clean_string($string) {
    $bad = array("content-type","bcc:","to:","cc:","href");
    return str_replace($bad,"",$string);
}
$data = clean_string($data);

After that strip the html tags to prevent html from being sent(prevents javascript from being sent as example). 之后,删除html标签以阻止html发送(以防止发送javascript为例)。

$data = strip_tags($data);

The data should be safe to send in a email now keep in mind the data is not safe yet to be sent to a sql database, if you do sent it to a databse use prepared statements so the data can't do any sql injections. 现在,数据应该可以安全地通过电子邮件发送,请记住,如果将数据发送到数据库,请使用准备好的语句将数据发送到sql数据库,因此尚不安全,因此数据无法进行任何sql注入。

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

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