简体   繁体   English

联系表单-使“发件人” URL看起来不像邮件正文中的URL,以避免将msg视为垃圾邮件?

[英]Contact form - make the “from” url not looking like an url in the body of the message to avoid msg to be considered as spam?

I have a contact form at the bottom of each page of my website. 我的网站每页底部都有联系表格。 Messages are sent thanks to the code below. 通过以下代码发送消息。 It works great but the fact that in the body of the message the URL from where the message was sent appears like this "From site: http://www.mywebsite.com/page2.htm " makes the message going to my spam items every time (I know I could flag it as non-spam etc.). 效果很好,但事实是,在邮件正文中,发送邮件的URL如下所示:“来自站点: http : //www.mywebsite.com/page2.htm ”,使该邮件进入了我的垃圾邮件项目每次(我知道我可以将其标记为非垃圾邮件等)。

Is there a way to make the URL (retrieved by . $_SERVER['HTTP_REFERER'] ) not looking like an url in the body of the message ie but inputing spaces btw www and .com or any other solution? 有没有一种方法可以使URL(由. $_SERVER['HTTP_REFERER']检索)看起来不像消息正文中的URL,即在www和.com之间输入空格或其他解决方案?

Many thanks 非常感谢

sendmessage.php: sendmessage.php:

<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {

  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }

  //send email
 mail( "contact@dfsdfds.com", "New message from: ".$_POST['name'], $_POST['message']."\nFrom site: ". $_SERVER['HTTP_REFERER'], "From:" . $_POST['email'] . "\r\n" . "BCC: dfds@gmail.com" );

}
?>

scripts.js: scripts.js:

// Contact Form
$(document).ready(function() {
    $("#contactfrm").submit(function(e) {
        e.preventDefault();
        var name = $("#name").val();
        var email = $("#email").val();
        var message = $("#message").val();
        var dataString = 'name=' + name + '&email=' + email + '&message=' + message;

        function isValidEmail(emailAddress) {
            var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
            return pattern.test(emailAddress);
        };
        if (isValidEmail(email) && (message.length > 1) && (name.length > 1)) {
            $.ajax({
                type: "POST",
                url: "sendmessage.php",
                data: dataString,
                success: function() {
                    $('input[name="submit"]').hide();
                    $('.error').hide()
                    $('.success').fadeIn(1000);
                }
            });
        } else {
            $('.error').fadeIn(1000);
        }
        return false;
    });
});

Perhaps you need to cut off the http:// in front of the url, like this: 也许您需要在URL前面切断http://,例如:

str_replace("http://", "", $_SERVER['HTTP_REFERER'])

If you want to put spaces between the . 如果您想在之间插入空格。 com (etc.) you could also do it with str_replace ( look up for detail ). com(等),您也可以使用str_replace( 查找详细信息 )。 But I don't think you need the put spaces into the url, because most spam-filters scan for the http:// part for link-detection. 但是我认为您不需要在URL中放置空格,因为大多数垃圾邮件过滤器都会扫描http://部分以进行链接检测。 Another reason why your EMail is filterd could be the short text or the unknown sending-server. 过滤电子邮件的另一个原因可能是短文本或未知的发送服务器。

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

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