我正在使用Remodal插件在我的网站上显示模态。 (https://github.com/VodkaBears/Remodal)这对我的需求非常有用。这是我第一次使用模态和电子邮件表单。我有一个提交表单的脚本,看起来像这样;
<form name="contact" id="contact" class="contact" method="post">
<label for="name">
<span>Name</span>
<input type="text" name="name" required="true" />
</label>
<label for="email">
<span>Email</span>
<input type="email" name="email" required="true" />
</label>
<label for="phone">
<span>Phone</span>
<input type="text" name="phone" required="true" />
</label>
<label for="message">
<span>Your message</span>
<textarea name="message" required="true"> </textarea>
</label>
<label>
<br>
<span> </span>
<input type="submit" class="send" value="Send"/>
</label>
</form>
这是我提交表单的脚本;
$(document).on('click', '.send', function () {
$.ajax({
type: "POST",
url: "mail.php",
data: $('form.contact').serialize(),
success: function (msg) {
$("#thanks").html(msg)
$("form.contact").modal('hide');
},
error: function () {
alert("Error.");
}
});
return false;
});
Mail.php:
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "my@email.com";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$message = $_REQUEST['message'];
//send email
mail($admin_email, "New e-mail", $message, "From:" . $email);
//Email response
echo "Thank you!";
}
?>
我在某个地方找到了这个代码,我正在尝试将它实现到我的表单中。有用!但是,我没有得到任何成功的消息或错误消息。我试图把它包裹起来,但是无法理解它。有人可以帮忙吗?