我的联系表格是两次发送电子邮件,我无法弄清楚为什么.. 当我提交表单时,发送消息和成功消息会显示两次,我也会收到两次电子邮件。
您可以在www.dev-kevin.compoint.be/ctrl+/
上找到该表单我找不到问题......
形式:
<form id="main-contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Naam" required>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="tel" name="tel" class="form-control" placeholder="Telefoon" required>
</div>
<div class="form-group">
<textarea name="message" class="form-control" rows="8" placeholder="Bericht" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Verstuur</button>
</form>
sendemail.php:
<?php
$name = @trim(stripslashes($_POST['name']));
$from = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['tel']));
$message = @trim(stripslashes($_POST['message']));
$to = "kevin@compoint.be";
$mensaje = "Naam: $name \nEmail: $from \nTelefoon: $subject \nBericht: $message";
$pagetitle = "Bericht via de website";
$from = "FROM: Website <info@ctrl+.be>\r\n";
mail($to, $pagetitle, $mensaje, $from);
die();
使用Javascript:
// Contact form
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email versturen...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">Uw bericht is succesvol verzonden. Wij nemen zo spoedig mogelijk contact met u op.</p>').delay(1000).fadeOut();
});
});