引导表单 - 无法添加字段

时间:2014-10-24 14:03:38

标签: php twitter-bootstrap

我有一个Twitter bootstrap现代商业网站,并希望在表单中添加两个字段。该表格表示已发送但未收到任何内容。

继承我的表格并联系-me.php



<form name="sentMessage" id="contactForm" novalidate>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Full Name:</label>
                            <input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
                            <p class="help-block"></p>
                        </div>
                    </div>
                    
                   
                    
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Foo:</label>
                            <input type="text" class="form-control" id="foo" required data-validation-required-message="foo.">
                            <p class="help-block"></p>
                        </div>
                    </div>
                    
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Foo2:</label>
                            <input type="text" class="form-control" id="foo2" required data-validation-required-message="foo2.">
                            <p class="help-block"></p>
                        </div>
                    </div>
                    
                                        
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Phone Number:</label>
                            <input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
                        </div>
                    </div>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Email Address:</label>
                            <input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
                        </div>
                    </div>
                    <div class="control-group form-group">
                        <div class="controls">
                            <label>Message:</label>
                            <textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
                        </div>
                    </div>
                    <div id="success"></div>
                    <!-- For success/fail messages -->
                    <button type="submit" class="btn btn-primary">Send Message</button>
                </form>
&#13;
&#13;
&#13;

和我的联系我-php

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['foo'])         ||
   empty($_POST['foo2'])        ||
   empty($_POST['phone'])       ||
   empty($_POST['email'])       ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$foo = $_POST['foo'];
$foo2 = $_POST['foo2'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];

// create email body and send it    
$to = 'foo@foo.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Modern Business Contact Form:  $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nfoo: $foo\n\nfoo2: $foo2\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@your-domain.com\n";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

3 个答案:

答案 0 :(得分:0)

  • 检查,验证并过滤POST数据以查看数据是否正确通过
  • 确认您可以从正在使用的服务器发送邮件并正确设置配置(SMTP等)
  • 考虑using a mail library,而不是手动处理容易出错的邮件标题,正文内容以及所有涉及的内容
  • 您的电子邮件可能是classified as spam,因此无法通过

答案 1 :(得分:0)

我认为你应该有一个名字&#34;归因于您的输入。它们不是有效的控件,source

答案 2 :(得分:0)

感谢您的帮助。我把萤火虫放在上面,发现我错过了POST数据。经过一段时间的努力,我发现我必须编辑我的contact_me.js(有帮助地说不要在模板中编辑它)再次感谢!