gpt4 book ai didi

javascript - 消息提醒不起作用

转载 作者:行者123 更新时间:2023-12-03 05:48:45 25 4
gpt4 key购买 nike

这是我的代码,问题是当我发送电子邮件调用表单 ID 时,电子邮件不会发送,当我删除表单 ID 时,电子邮件正在发送

html代码,html后面是js代码这是我的代码,问题是,当我发送电子邮件调用表单 ID 时,电子邮件不会发送,当我删除表单 ID 时,电子邮件正在发送

<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>

--

ajax代码

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">' + data.message + '</p>').delay(3000).fadeOut();
});
});

php代码

               <?php


header('Content-type: application/json');


$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);




$name = @trim(stripslashes($_POST['name']));


$email = @trim(stripslashes($_POST['email']));


$subject = @trim(stripslashes($_POST['subject']));


$message = @trim(stripslashes($_POST['message']));



$email_from = $email;



$email_to = 'email@email.com';//replace with your email




$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;




$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');





echo json_encode($status);



die;

最佳答案

这就是您的 ajax 调用的样子

$('#main-contact-form').on('submit', function(event) {
event.preventDefault();

var form_status = $('<div class="form_status"></div>');

$.ajax({
url : $(this).attr('action'),
data : $(this).serialize(),
dataType : 'json',
type : 'POST',
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">' + data.message + '</p>').delay(3000).fadeOut();
});
});

关于javascript - 消息提醒不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232629/

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