php发送空白电子邮件

时间:2017-12-02 21:33:36

标签: javascript php email

出于某种原因,我们每天从支持页面收到大约5/10封电子邮件,这些电子邮件是空的,没有填写输入字段,但根本没有提取输入字段。电子邮件仅显示主题。

如果我们测试表单它工作正常,电子邮件显示我们填写的信息,即使我们没有填写任何东西,我们仍然收到一封电子邮件,说明输入字段名称。在网站对支持页面上的用户进行的录制中,在我们收到“空白”电子邮件时,似乎没有用户填写表单。

我会帮忙,因为我完全迷失了如何解决这个问题。

使用Javascript:

$( document ).ready(function() {
      var $form = $('form');
      $form.submit(function() {
        $.post($(this).attr('action'), $(this).serialize(), function(response) {


            $('.email-popup-container').css({
               "transform": "scale(.9)",
          });


            setTimeout(function(){

          $('.email-popup-container').animate({
             "margin-left": "+=1200px",
            "opacity": "0",
        }, 400, function(){

            setTimeout(function(){
                    $('#email-popup').removeClass('is-visible').ready(function(){

                        $('.email-popup-container').css({
                           "transform": "scale(1)",
                      });
                                $('#contact-form')[0].reset();
                                $('.email-popup-container').animate({
                                    "margin-left": "-=1200px",
                                }, 0
                            );
                    });
},150)
setTimeout(function(){
    $.notify(" Thank you! We have recieved your e-mail.", {
      delay: 4000,
      color: "#fff",
      background: "#1AC16D",
      type: "success",
      icon: "check",
      align: "right",
      animationType: "fade"
    });

},400)

          });




      },600)



        }, 'json');
        return false;
      });
    });

PHP:         

// configure
$from = 'New Message - Support Page <istillwebsite@donotreply.com>';
$sendTo = 'New Message - Support Page <sales@istillmail.com>';
$subject = 'Message from iStill Support Page';
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in email
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';

// let's do the sending

try
{
    $emailText = "Someone sent a message from the support page\n=============================\n";

    foreach ($_POST as $key => $value) {

        if (isset($fields[$key])) {
            $emailText .= "$fields[$key]: $value\n";
        }
    }

    mail($sendTo, $subject, $emailText, "From: " . $from);

    $responseArray = array('type' => 'success', 'message' => $okMessage);





}
catch (\Exception $e)
{
    $responseArray = array('type' => 'danger', 'message' => $errorMessage);
}

if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
    $encoded = json_encode($responseArray);

    header('Content-Type: application/json');

    echo $encoded;
}
else {
    echo $responseArray['message'];
}

?>

1 个答案:

答案 0 :(得分:1)

这是发送邮件的超级不安全方式。有人可以调用你的.php脚本并发送多封邮件。所以它可能是一个机器人或类似的东西,就是调用你的脚本。

为防止这种情况发生,您可以使用Google reCaptcha作为示例。