gpt4 book ai didi

javascript - 为什么我会收到一封空电子邮件?

转载 作者:行者123 更新时间:2023-12-03 07:09:53 26 4
gpt4 key购买 nike

为什么我的电子邮件中未包含字段值?我收到一封空电子邮件。

HTML

<div class="contact-form wow fadeIn" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="row">
<div class="col-sm-6">
<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<div class="col-sm-6">
<div class="form-group">
<input type="text" id="name" name="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" id="email" name="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" id="subject" name="subject" class="form-control" placeholder="Subject" required="required">
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit">Send Now</button>
</div>
</form>
</div>

JavaScript

var form = $('#main-contact-form');
form.submit(function(event) {
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
beforeSend: function() {
form.prepend(form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn());
}
}).done(function(data) {
form_status.html('<p class="text-success">Thank you for contact us. As early as possible we will contact you</p>').delay(6000).fadeOut();
});
});

PHP

<?php

$name = @trim(stripslashes($_POST['name']));
$headers = 'From:'. @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$temp_name = 'Client name='.$name."\n\n\n";
$temp_text = 'client query='.@trim(stripslashes($_POST['message']));
$message = $temp_name.$temp_text;
$to = 'svasu1850@gmail.com';

if(@mail($to, $subject, $message, $headers))
{
$result="Thanks for contacting us";
}else{
$result="retry after some time";
}

?>

最佳答案

您正在使用 JavaScript 来阻止默认表单提交。这会停止发布用户的输入,除非您捕获它并选择在 ajax 代码中发送它。

$.ajax({
...
data: $("#main-contact-form").serialize(),
...
})

在此处查看更多信息:jQuery - Getting form values for ajax POST

关于javascript - 为什么我会收到一封空电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36652932/

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