2 回答
TA贡献1796条经验 获得超4个赞
<script>
$(function () {
$("#myForm").submit(function (evenr) {
event.preventDefault(e);
var form_data = $(this).serialize();
$.ajax({
url:'mail.php',
method:'POST',
data:{data},
success:function(data){
alert(data);
if($.trim(data))
{
alert("Mail was sent !")
$("#success_message").attr("style", "display: none");
}else{ alert("Mail was not sent !")}
}
});
});
});
</script>
Ajax 文件更改:
if(isset($_POST['name']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['service'])) {
$to = 'test@gmail.com';
$subject = "{$_POST['name']} " . ' Requested the Pest Control Services';
$message = '
<html>
<head>
<title>Pest Control Services</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Phone:</b> ' . $_POST['phone'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Services Type:</b> ' . $_POST['service'] . '</p>
</body>
</html>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From:{$_POST['name']} {$_POST['email']}\r\n";
if(mail($to, $subject, $message, $headers)){
echo "1"; exit;
else{
echo "0"; exit;
}
}
TA贡献1824条经验 获得超5个赞
尝试这样的事情..
if((isset($_POST['name']))&&(isset($_POST['phone'])&&$_POST['email']&&$_POST['service'])) {
$to = 'ajerad30@gmail.com';
$subject = "{$_POST['name']} " . ' Requested the Pest Control Services';
$message = '
<html>
<head>
<title>Pest Control Services</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Phone:</b> ' . $_POST['phone'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Services Type:</b> ' . $_POST['service'] . '</p>
</body>
</html>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From:{$_POST['name']} {$_POST['email']}\r\n";
if(mail($to, $subject, $message, $headers))
{
echo "<script>alert('Mail was sent !');</script>";
}
else
{
echo "<script>alert('Mail was not sent. Please try again later');</script>";
}
}
- 2 回答
- 0 关注
- 209 浏览
添加回答
举报