PHP& Jquery发送电子邮件

时间:2016-11-30 19:38:07

标签: php jquery html

所以我试图让我的表单使用jquery发送电子邮件。我知道电子邮件是服务器端,所以我已将我的jquery连接到php,我想要做的是在从php文件发送电子邮件后收到警报,但我没有收到任何警报现在。

<!-- JS FILE -->
<script type="text/javascript" src="js/includes.js"></script>

<!-- HTML FORM -->
<div id="id01" class="modal">
<form class="modal-content animate" action="#" method="POST">
<div class="imgcontainer">
  <span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close">&times;</span>
</div>

<div class="container_form">
  <span><b>Account Information</b></span>
  <input id="email" type="email" placeholder="Enter Email Address" name="email_name" required>  
  <input id="lbutton" type="submit" value="Submit"/>
</div>

    

Java脚本代码:

$(function() { //shorthand document.ready function
    $('#lbutton').on('submit', function(e) { //use on if jQuery 1.7+
        e.preventDefault();  //prevent form from submitting

        $.ajax({
            type : 'POST',
            url : './helpers/sendmail.php',           
            data: {
                action: "lost_info",
                email   : $('#email').val()
                },
            success:function (data) {
                if (data == "sent")
                    alert("An email has been sent to you, please check your email");
                else
                    alert("Something went wrong, please try again");
            }      
        });     
    });
});

用于测试的PHP代码:

<?php
  echo "sent";
?>

0 个答案:

没有答案