我有这个免费模板,但联系表格根本不起作用。它说消息已发送但我没有收到任何电子邮件。表单看起来非常好,这就是为什么我不想改变它,但它不起作用。开发人员不提供免费模板的技术帮助。请帮助我,并提前感谢你!
HTML
<form id="main-contact-form" name="contact-form" role="form" method="post" action="sendemail.php">
<div class="form_status" style="display: none;"><p class="text-success">Thank you for contacting us. We'll get back to you shortly.</p></div>
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email" required>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject" required>
</div>
<div class="form-group">
<textarea name="message" class="form-control" rows="8" placeholder="Message" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
PHP
<?php
$name = @trim(stripslashes($_POST['name']));
$from = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$to = 'nikita_lim@rocketmail.com';//replace with your email
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
JS
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
url: '../sendemail.php',
//type : $(this).attr('method'),
//data : $(this).serialize(),
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 contacting us. We will get back to you shortly</p>').delay(3000).fadeOut();
});
});
答案 0 :(得分:2)
发布为社区维基。
您的邮件标题失败了。
因此,根据手册中的说明添加implode("\r\n", $headers)
:
手册中的示例:
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender@domain.com>";
$headers[] = "Bcc: JJ Chong <bcc@domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver@domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $email, implode("\r\n", $headers));
?>