联系表单发送电子邮件但没有用户输入

时间:2014-10-02 08:05:21

标签: php html forms twitter-bootstrap contact-form

这个使用html / php联系表单的bootstrap给我发了一封电子邮件就好了,但没有任何用户输入信息!

我收到的电子邮件看起来像这样空: 名称: 电子邮件: 学科: 消息:

表单的html是:

	<section id="partner">
        <div class="container">
            <div class="center wow fadeInDown">        
                <h2><br>Contact</h2>
                <p class="lead">Send a general enquiry here or order your service here.</p>
            </div> 
            <div class="row contact-wrap"> 
                <div class="status alert alert-success" style="display: none"></div>
                <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> 
            </div><!--/.row-->
        </div><!--/.container-->
    </section><!--/#contact-page-->

表单的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 = 'heerschapnikki@gmail.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;

为什么它不能正常工作? “感谢您与我们联系”的消息弹出正常,电子邮件通过,但没有用户信息通过。

2 个答案:

答案 0 :(得分:0)

尝试打印您要发送的值。所以使用这个:

var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...

这样做,您将能够看到您的字段甚至被正确发布。

答案 1 :(得分:0)

字段没有id参数。在帖子中你得到“id”和“名字”

    <label>Name *</label>
    <input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
    <label>Email *</label>
    <input type="email" id="email" class="form-control" required="required">