PHP 表单发送但 "No Sender"

PHP form sends but "No Sender"

我能够收到包含除在表单中输入的电子邮件地址以外的所有信息的电子邮件,并且当我收到电子邮件时,我收到 "No Sender" 而不是该人的姓名或电子邮件。

这是我的 HTML:

        <!-- Contact Form -->
        <div class="col-xs-12 col-sm-8 col-md-8">
            <div id="contant-form-bx" class="contant-form-bx">
                <div class="contact-loader"></div>
                <form action="mail.php" id="contact-form" class="contact-form" name="cform" method="post">
                    <div class="row">
                        <div class="col-md-6">  
                            <label for="name" id="name_label">Name</label>
                            <span class="name-missing">Please enter your name!</span>  
                            <input id="name" type="text" value="" name="name" size="30"> 
                        </div> 
                        <div class="col-md-6 columns"> 
                            <label for="e-mail" id="email_label">Email</label>
                            <span class="email-missing">Please enter a valid e-mail!</span> 
                            <input id="e-mail" type="text" value="" name="email" size="30">
                        </div>
                        <div class="col-md-12"> 
                            <label for="message" id="phone_label">Message</label>
                            <span class="message-missing">Say something!</span>
                            <textarea id="message" name="message" rows="7" cols="40"></textarea>
                        </div>
                        <div class="col-md-12 text-center"> 
                            <input type="submit" name="submit" class="button" id="submit_btn" value="Send Message">  
                        </div>
                    </div>
                </form>
            </div>
        </div>

这是我的 PHP:

    <?php
// declare our variables
$name = $_POST['name'];
$email = $_POST['e-mail'];
$message = nl2br($_POST['message']);

// set a title for the message
$subject = "From $name via WEB";
$body = "From $name, \n\n$message";
$headers = 'From: '.$email.'' . "\r\n" .
    'Reply-To: '.$email.'' . "\r\n" .
    'Content-type: text/html; charset=utf-8' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

// put your email address here
mail("info@wziel.com", $subject, $body, $headers);
?>

<!--Display a Thank you message in the callback -->
<div class="mail_response">
    <h4>Thank you <?php echo $name ?>!</h4>
    <p>I'll be in touch real soon!</p>
</div> 

根据您的表格:

$email = $_POST['e-mail'];

应该是这样的:

$email = $_POST['email'];

您将 e-mail 作为 id 而不是 name

php 关注 name 而不是 id

您正在使用 $_POST['e-mail']e-mail<input> 标签的 ID。你应该使用 $_POST['email'] 因为 name="email".