PHP电子邮件表单未张贴姓名或电话号码

PHP电子邮件表单未张贴姓名或电话号码,php,forms,email,Php,Forms,Email,我似乎不明白为什么我的php没有将姓名和电话号码发送到电子邮件中。电子邮件和信息工作正常 这是我的HTML: <form method="POST" name="contact_form" action="php.php"> <label for='fname'>Name: </label> <input type="text" name="fname"> <label for='email'>Email: </label>

我似乎不明白为什么我的php没有将姓名和电话号码发送到电子邮件中。电子邮件和信息工作正常

这是我的HTML:

<form method="POST" name="contact_form" action="php.php"> 
<label for='fname'>Name: </label>
<input type="text" name="fname">
<label for='email'>Email: </label>
<input type="text" name="email">
<label for='phone'>Phone: </label>
<input type="text" name="phone">
<label for='message'>Message:</label>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
<label><img src="/captcha.php"></label>
<input type="text" name="code" value="Please enter the code"> <br />
<input type="submit" value="Submit" name='submit' class="quoteButton">
</form>   

姓名:
电邮:
电话:
信息:

以下是我的PHP:
session_start();

if (isset($_POST['submit'])) {
    $error = "";

    if (!empty($_POST['fname'])) {
    $name = $_POST['fname'];
    } else {
    $error .= "You didn't type in your name. <br />";
    }

            if (!empty($_POST['phone'])) {
    $name = $_POST['phone'];
    } else {
    $error .= "You didn't enter your phone. <br />";
    }

    if (!empty($_POST['email'])) {
    $email = $_POST['email'];
      if (!preg_match("/^[a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){ 
      $error .= "The e-mail address you entered is not valid. <br/>";
      }
    } else {
    $error .= "You didn't type in an e-mail address. <br />";
    }

    if (!empty($_POST['message'])) {
    $message = $_POST['message'];
    } else {
    $error .= "You didn't type in a message. <br />";
    }

if(($_POST['code']) == $_SESSION['code']) {
$code = $_POST['code'];
} else {
$error .= "The captcha code you entered does not match. Please try again. <br />";    
}

    if (empty($error)) {
    $from = 'From: ' . $fname . ' <' . $email . '>';
    $to = "mail@domain.com"; 
    $subject = "New contact form message";
    $content = $fname . " has sent you a message. \nEmail: $email \nPhone:  $phone \nMessage: \n" . $message;
    $success = header( 'Location: '' ) ;
    mail($to,$subject,$content,$from);
    }
    }
?>
session_start();
如果(isset($_POST['submit'])){
$error=“”;
如果(!空($_POST['fname'])){
$name=$_POST['fname'];
}否则{
$error.=“您没有输入您的姓名。
”; } 如果(!空($_POST['phone'])){ $name=$_POST['phone']; }否则{ $error.=“您没有输入手机。
”; } 如果(!空($_POST['email'])){ $email=$_POST['email']; 如果(!preg_match(“/^[a-z0-9]+(\.[U a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i,$email)){ $error.=“您输入的电子邮件地址无效。
”; } }否则{ $error.=“您没有键入电子邮件地址。
”; } 如果(!空($_POST['message'])){ $message=$_POST['message']; }否则{ $error.=“您没有键入消息。
”; } 如果($_POST['code'])==$_SESSION['code'])){ $code=$_POST['code']; }否则{ $error.=“您输入的验证码不匹配。请重试。
”; } if(空($error)){ $from='from:'.$fname'; $to=”mail@domain.com"; $subject=“新联系人表单消息”; $content=$fname.“已向您发送消息。\n邮件:$email\n电话:$phone\n消息:\n.“$message; $success=标题('位置:“”); 邮件($to,$subject,$content,$from); } } ?>
任何帮助都将不胜感激。谢谢

1)您将变量命名为名字
$name
,但在代码的电子邮件部分使用
$fname

$name = $_POST['fname'];
$name = $_POST['phone'];
应该是

$fname = $_POST['fname'];
$phone = $_POST['phone'];
2) 您将变量命名为first name
$name
(覆盖初始赋值),但在代码的电子邮件部分使用
$phone

$name = $_POST['fname'];
$name = $_POST['phone'];
应该是

$fname = $_POST['fname'];
$phone = $_POST['phone'];

如果启用完全错误报告,您应该会收到有助于发现问题的通知。