我有一个基本联系表单构建的响应式网站。我正在尝试使用过去使用过的PHPHMailer。出于某种原因,我的表单中的值不是PHPMailer。我通过在“名称”,“电子邮件”,“主题”和“消息”中放置硬编码值进行测试,表单可以正常工作。我尝试使用“isset”来确保在尝试发送邮件之前是值(我这样做是因为没有“isset”我得到一个“未定义的索引”错误,告诉我没有值。这段代码在我的工作正常基本形式没有响应,但没有响应。我很难过。任何建议都会受到欢迎。这是我的html和PHP的代码。谢谢!*我已经更新了代码,因为我已经将问题缩小到Java脚本。在HTML中,“form id =”main-contact-form“触发了以下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'),
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(3000).fadeOut();
});
});
正是这个问题导致了这个问题。我目前正试图弄清楚为什么会这样。感谢那些曾试图提供帮助的人。
<form id="main-contact-form" name="contact-form" method="post" action="contact.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" name="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" 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>
我的PHP;
<?php
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$message = $_REQUEST['message'];
$subject = $_REQUEST['subject'];
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'myhost.com';
$mail->SMTPAuth = true;
$mail->Username = 'me@myemail.com';
$mail->Password = 'mypassword';
$mail->SMTPSecure = 'tls';
$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress('me@myemail.com');
$mail->addReplyTo($email);
$mail->WordWrap = 50;
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
答案 0 :(得分:0)
在您的代码中检查一下,您在提交按钮
中缺少此名称php app/console doctrine:schema:update --force
并替换此
<button type="submit" class="btn-submit" name='submit'>Send Now</button>
用这个
$email = $_POST['email'];
$name = $_POST['name'];
$message = $_POST['message'];
$subject = $_POST['subject'];
答案 1 :(得分:0)
对于有这个问题的其他人。一旦我终于明白了,解决方案就非常简单了。正在使用的main.js模板不传递数据并输入ajax代码。你需要添加类型:&#34; POST&#34;和data:form.serialize()到ajax。见下文。
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
type:"POST",//new
url: $(this).attr('action'),
data: form.serialize(), //new
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
在
&#39;。)