gpt4 book ai didi

javascript - 电子邮件表格未发送

转载 作者:行者123 更新时间:2023-12-03 12:30:41 24 4
gpt4 key购买 nike

我在提交此电子邮件表单时遇到问题。email.php 文件位于根目录中,如下所示:

<?php
$val= $_POST['val'];
$toemail='someone@gmail.com';
$name = $val['name'];
$email = $val['email'];
$msg = $val['msg'];

$subject = 'Message from zachjanice.com';

$headers = "From: zachjanice.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

&nbsp;

$message = "<b>Name :</b>".$name."<br>";
$message .='<b>Email :</b>'.$email."<br>";
$message .='<b>Message :</b>'.$msg;
mail($toemail, $subject, $message, $headers);

echo "Thanks for contacting me!";

?>

我正在使用 validate.js 来验证表单并 Bootstrap 样式。这是 HTML:

<form class="contactform" role="form">
<div class="form-group">
<label class="control-label">Name</label>
<div class="controls">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name">
</div>
</div>
</div>

<div class="form-group">
<label class="control-label">Email</label>
<div class="controls">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span>
<input type="text" class="form-control" id="email" name="email" placeholder="Email">
</div>
</div>
</div>

<div class="form-group ">
<label class="control-label">Message</label>
<div class="controls">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<textarea name="msg" class="form-control " rows="4" cols="78" placeholder="Enter your message here"></textarea>

</div>
</div>
</div>

<div class="controls" style="margin-left: 40%;">

<button type="submit" id="mybtn" class="btn btn-primary">Send Message</button>

</div>
</form>

我忘了这是我的 JS:

$(document).ready(function(){
$.validator.setDefaults({
submitHandler: function(form) {
$.ajax({
type: "POST",
url: "email.php",
data: { 'val':$(".contactform").serializeJSON() }
}).done(function(data) {
alert(data);

});
}
});
$(".contactform").validate(
{rules:
{name:"required",
email:{required:true,email:true},
website:{required:false,url:true},
cate:"required",
msg:{required:true, maxlength:300
}},
errorClass:"error",
highlight: function(label) {
$(label).closest('.form-group').removeClass('has-success').addClass('has-error');
},

success: function(label) {
label
.text('Seems Perfect!').addClass('valid')
.closest('.form-group').addClass('has-success');
}
});
});

非常感谢您的帮助。如果可能的话,我想今晚完成这个网站,但此时我有点慌张。

最佳答案

尝试var_dump(mail($toemail, $subject, $message, $headers));

您将获得一些有用的信息。

还要检查变量 $name、$email$msg 是否已填充,如果没有,请执行以下操作:$name = $_POST['name ']

关于javascript - 电子邮件表格未发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23943117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com