【问题标题】:getting spam email from myself php收到我自己的垃圾邮件php
【发布时间】:2014-07-18 17:28:26
【问题描述】:

我有一个用普通 HTML 构建的网站,只有一个页面是 php,用于从联系我们页面生成电子邮件。 现在发生了什么,我的联系页面工作正常,但我每天凌晨 3:10 到凌晨 3:12 都会收到电子邮件,其中包含相同的垃圾条目“1” 例如:
名称:1
电子邮件:我自己的电子邮件地址(与发件人(我自己)的电子邮件地址相同)
公司:1
地址:1

这是我遇到的主要问题。我正在使用验证码来防止垃圾邮件。 请帮助:请参阅我使用过的以下代码: PHP 电子邮件代码(example-form.php):

    <?php session_start(); ?>
    <?php
    /** Validate captcha */
    if (!empty($_REQUEST['captcha'])) {
    if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) !=          $_SESSION['captcha']) {
      header('Location: /captchacode.html');
      exit();
      //die("The verification code didn't match what was expected.");
      //echo '<script>window.location.assign("/captchacode.html")</script>';
     }
     unset($_SESSION['captcha']);
    }
    if(thankyou_mail()){
    $rediect = $_REQUEST['redirect'];
        $_REQUEST ='';
    //header("Location :".$_REQUEST['redirect']);
    echo '<script>window.location.assign("'.$rediect.'")</script>';
    }else{

       //header("Location:404.html");
        echo '<script>window.location.assign("/404.html")</script>';   
    }
    function thankyou_mail() {
    # Localize variables used in this subroutine.
    $to =$_REQUEST['email'];
    //$headers = "From:".$_REQUEST['recipient']."(".$_REQUEST['realname'].")\r\n";
    //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $date=date("Y/m/d");

    # Check for Message Subject
    $subject =$_REQUEST['subject'];

    $message ="Thank You For Filling Out This Form.</b>";
    $message .= "Below is what you submitted to ".$_REQUEST['recipient']." on ";
    $message .="$date<p><hr size=1 width=75\%><p>\n";    
    $message .="<b> Name:</b> ".$_REQUEST['name']."<p>\n";
    $message .="<b> Email:</b> ".$_REQUEST['email']."<p>\n";
    $message .="<b> Company:</b> ".$_REQUEST['company']."<p>\n";
    $message .="<b> Address:</b> ".$_REQUEST['address']."<p>\n";
    $message .="<b> City:</b> ".$_REQUEST['city']."<p>\n";
    $message .="<b> State:</b> ".$_REQUEST['state']."<p>\n";
    $message .="<b> Zip:</b> ".$_REQUEST['zip']."<p>\n";
    $message .="<b> Questions/Comments:</b> ".$_REQUEST['message']."<p>\n";


    $headers = "From:".$_REQUEST['FormName']."<".$_REQUEST['from'].">\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    //send_mail();
    if ($to == $_REQUEST['from'])
    {
        header ('Location: /emailerror.html');
        exit();
    }
    if(mail($to,$subject,$message,$headers)){
        return true;    
    }else{
        return false;
    }
    //mail($to,$subject,$message,$headers);
    // return true;
    }
    /*
    function send_mail() {


    # Localize variables used in this subroutine.
    $to =$_REQUEST['recipient'];
    $headers = "From:".$_REQUEST['email']."(".$_REQUEST['realname'].")\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


    # Check for Message Subject
    $subject =$_REQUEST['subject'];

    $message  ="Below is the result of your feedback form.  It was submitted by\n";
    $message .= $_REQUEST['realname']." (".$_REQUEST['email'].") on $date<p><hr size=1   width=75\%><p>\n"; 
    $message .="<b> Name:</b> ".$_REQUEST['name']."<p>\n";
    $message .="<b> Email:</b> ".$_REQUEST['email']."<p>\n";
    $message .="<b> Company:</b> ".$_REQUEST['company']."<p>\n";
    $message .="<b> Address:</b> ".$_REQUEST['address']."<p>\n";
    $message .="<b> City:</b> ".$_REQUEST['city']."<p>\n";
    $message .="<b> State:</b> ".$_REQUEST['state']."<p>\n";
    $message .="<b> Zip:</b> ".$_REQUEST['zip']."<p>\n";
    $message .="<b> Questions/Comments:</b> ".$_REQUEST['message']."<p>\n";
    mail($to,$subject,$message,$headers);
    return true;
    }
    */

联系我们(HTML 页面)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Contact Us - </title>
    <meta name="keywords" content="KEYWORDS GO HERE. 12 KEYWORDS MAX, & ONLY 3 REPEATED WORDS" /> 
    <meta name="description" content="DESCRIPTION GOES HERE. 160 CHARACTERS" />

    <link rel="stylesheet" type="text/css" href="styles.css" title="standard" />
    <link rel="icon" href="/images/favicon.ico" />

    <script src="scripts/rollover.js" type="text/javascript"></script>

    </head>

    <script src="lib/jquery.js"></script>
    <script src="jquery.validate.js"></script>

    <script>
    //$.validator.setDefaults({
    //  submitHandler: function() {  }
    //});

    $().ready(function() {

    // validate signup form on keyup and submit
    $("#signupForm").validate({
        rules: {


    name: {
                required: true,
                minlength: 2
            },
            email: {
                required: true,
                email: true
            },
            company: {
                required: true,
                minlength: 5
            },
            address: {
                required: true,
                minlength: 2
            },
            city: "required",
            state: "required",
            zip: "required",
            captcha:"required"
        },

        messages: {
            name: {
                required: "Please enter a username",
                minlength: "Your username must consist of at least 2 characters"
            },
            company: "Please enter a company",

            email: "Please enter a valid email address",
            address: "Please enter a address",
            city: "Please enter a city",
            state:"Please enter a state",
            zip: "Please enter a zip",
            captcha : "Please enter a letters of Image"
        }
    });


    });
    </script>

    <style type="text/css">

     label.error {
    margin-left: 10px;
    width: auto;
    display: inline;
    color: red;
    }
    #newsletter_topics label.error {
    display: none;
    margin-left: 103px;
    }
    </style>


    <body>
    <div id="headerWrap">
    <div id="header">
        <h1 id="logo">LLC</h1>
        <div id="contact"><a href="contact.html">CONTACT US</a></div>
    </div><!-- end #header -->
    </div><!--  end #headerWrap  -->

    <div id="navWrap">
    <div id="nav">
        <ul class="nav1">
        <li><a href="index.html"><img class="imgover" src="images/nav-home.jpg"  width="129" height="46" /></a></li>
        <li><a href="about.html"><img class="imgover" src="images/nav-about.jpg" width="135" height="46" /></a></li>
        <li><a href="lobbying.html"><img class="imgover" src="images/nav-lobbying.jpg" width="168" height="46" /></a></li>
        <li><a href="ally-development.html"><img class="imgover" src="images/nav-ally.jpg" width="237" height="46" /></a></li>
        <li><a href="strategic-consulting.html"><img class="imgover" src="images/nav-strategic.jpg" width="231" height="46" /></a></li>
        </ul>
    </div><!-- end #nav -->
    </div><!--  end #navWrap  -->

    <div id="contentWrap">

    <div id="content">

    <br clear="all" />

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
        <td class="c2L">
            <div><a href="contact.html"><img src="images/contact.jpg" /></a></div>
        </td>
        <td class="c2R">
            <div>
            <h2 class="normh2">Contact Us</h2>

            <form method="post"  id="signupForm" action="example-form.php">
                <input name="FormName" type="hidden"  />
             <!--   <input name="username" type="hidden"  />-->
                <input name="realname" type="hidden"  />
                <input name="subject" type="hidden"  />
                <input name="thankurl" type="hidden" value="thank.html" />
              <!--  <input name="recipient" type="hidden" value="emailid" />-->
                <input name="email" type="hidden" value="" />
                <input name="redirect" type="hidden" value="/thank.html" />

                <input type="hidden" name="from"  />

            <table id="contactTable" width="100%" cellspacing="0" cellpadding="0">
                <tr>
                <td id="contactTableL">Name</td>
                <td id="contactTableR"><input type="text" name="name" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">Email</td>
                <td id="contactTableR"><input type="text" name="email" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">Company</td>
                <td id="contactTableR"><input type="text" name="company" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">Address</td>
                <td id="contactTableR"><input type="text" name="address" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">City</td>
                <td id="contactTableR"><input type="text" name="city" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">State</td>
                <td id="contactTableR"><input type="text" name="state" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">Zip</td>
                <td id="contactTableR"><input type="text" name="zip" size="35" /></td>
                </tr>
                <tr>
                <td id="contactTableL">Questions/<br />Comments</td>
                <td id="contactTableR"><textarea name="message" rows="9" cols="31" ></textarea></td>
                </tr>
                 <tr>
                <td id="contactTableL">Verification<br />
        <img src="captcha.php" id="captcha" /><br/>


    <!-- CHANGE TEXT LINK -->
     <a href="javascript:void(0)" onclick="      document.getElementById('captcha').src='captcha.php?'+Math.random();
    document.getElementById('captcha-form').focus();"
    id="change-image">Not readable? Change text.</a>
    </td>
                <td id="contactTableR">
            <input type="text" name="captcha" id="captcha-form"  autocomplete="off" />
            </td>
                </tr>
                <tr>
                <td>&nbsp;</td>
                <td><input id="submitButton" type="submit" name="submit" value="SUBMIT" /></td>
                </tr>
            </table>
            </form>

            </div>
        </td>
        </tr>
    </table>

    </div><!--  end #content  -->

     </div><!--  end #contentWrap  -->

    <div id="footerWrap">

    <div id="footer">

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
        <td class="c2L2">
            <div><img src="images/logo-footer.jpg" alt="" width="216" height="103"   /></div>
        </td>
        <td class="c2R2">
            <ul class="nav2">
                <li><a href="index.html">HOME</a></li>
                <li><a href="about.html">ABOUT</a></li>
                <li><a href="lobbying.html">LOBBYING</a></li>
                <li><a href="ally-development.html">ALLY<br />DEVELOPMENT</a></li>
                <li><a href="strategic-consulting.html">STRATEGIC<br />CONSULTING</a></li>
                <li class="last"><a href="contact.html">CONTACT US</a></li>
            </ul>
            <br clear="all" />

            <p><span>Copyright &copy; 2012 LLC</span> Website Design by <a       href="http://www.2broz.com">Web Design CT</a></p>
        </td>
        </tr>
    </table>

    </div><!--  end #footerContain  -->

    </div><!--  end #footerWrap  -->

     </body>
    </html>

我认为这些是有用的代码,如果您需要更多帮助,请告诉我。

【问题讨论】:

    标签: php email captcha


    【解决方案1】:

    您的 if-else 子句中有一个逻辑错误:

    if (!empty($_REQUEST['captcha'])) {
        if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
            header('Location: /captchacode.html');
            exit();
        }
        unset($_SESSION['captcha']);
    }
    

    如果有人填写了验证码,您只是在测试验证码是否正确。因此,如果有人在将验证码留空的情况下设法发送表单,则测试将通过,邮件将被发送。如果您将测试更改为以下内容,它应该可以工作:

    if( empty($_REQUEST['captcha']) 
        || empty($_SESSION['captcha']) 
        || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) {
        // captcha not filled in, or captcha not correct.
    }
    

    【讨论】:

    • 我检查了验证码条件,它工作正常...当输入错误时重定向到错误页面并且未发送电子邮件。如果输入正确,则电子邮件
    • 是的,但是如果没有输入,它将通过测试......也许你的 javascript 正在检查是否发布了一个值,但你的 PHP 代码没有,而 javascript,我们都知道, 很容易被绕过。
    • 如果未输入,则不通过结果,验证码要求输入值。如果没有输入任何内容,我将不会收到电子邮件。
    • dude... 我不知道如何解释得更清楚... Captcha 依靠 javascript 进行第一次检查(不离开页面),以及 PHP 用于检查验证码是否正确.但是您要做的是检查验证码是否正确仅在输入某些内容时,这通常不会有问题,但是如果有人绕过JAVASCRIPT发送它数据直接写入您的脚本,您的检查失败...
    【解决方案2】:

    如果您能够看到垃圾邮件收件箱中的邮件,那么邮件代理的信誉就很低。尝试在标题中添加发件人地址并检查。

    这个问题前面已经回答过了。 PHP mail() form sending to GMAIL spam

    【讨论】:

    • OP 并不是说​​他在垃圾邮件收件箱中收到邮件,请正确阅读问题。
    猜你喜欢
    • 2012-11-10
    • 2012-07-24
    • 1970-01-01
    • 2019-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    相关资源
    最近更新 更多