Ajax阻止php邮件发送(我认为)

时间:2017-03-15 13:55:26

标签: javascript php jquery ajax email

我是PHP&的新手JS。当用户填写表单并单击提交时,我正在尝试淡出表单和淡入淡出消息。到目前为止,我已经取得了成功,但邮件不会发送。我做错了什么?

contact.php

<?php
if(isset($_POST['email'])) {

    function died($error) {
        // your error code can go here
        echo "Der er en fejl med de indtastede oplysninger fejl(ene) er <br />.";
        echo $error."<br /><br />";
        echo "Venligst gå tilbage og ret dem.<br /><br />";
        die();
    }


    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['mail']) ||
        !isset($_POST['tel'])) {
        died('Der er en fejl med de indtastede oplysninger.');       
    }

    $name = $_POST['name'];
    $email_from = $_POST['mail'];
    $tel = $_POST['tel']; 

    $email_to = "mail@mail.com"; // cut out on purpose.
    $email_subject = "$name ønsker at blive kontaktet";

    $email_message = "Denne Person vil gerne kontaktes!.\n\n";


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

    $email_message .= "Navn: ".clean_string($name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telefon: ".clean_string($tel)."\n";

// create email headers
$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: ". $email_to. "\r\n";
$headers .= "Reply-To: ". $email_from. "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
$headers .= "X-Priority: 1" . "\r\n"; 

mail($email_to, $email_subject, $email_message, $headers);  

?>

    <?php
}
?>

JS

$("#contact").on("submit", function (e) {
    e.preventDefault();
    var form = $(this);
    var post_url = form.attr("action");
    var post_data = form.serialize();
    $.ajax({
        type: "POST",
        url: "contact.php",
        data: post_data,
        success: function (msg) {
            $(form).fadeOut(500, function () {
                form.html(success).fadeIn();
            });
        }
    });
});

HTML

<div class="wow fadeInUp animated" data-wow-duration=".3" data-wow-delay=".1s" style="visibility: visible; animation-delay: 0.1s; animation-name: fadeInUp;" id="success">
    <div class="alert alert-success" role="alert">
        <strong>Super!</strong> Vi vender tilbage hurtigst muligt! :)
    </div>
</div>

我一直在看它,谷歌搜索2天,我找不到问题。

0 个答案:

没有答案