PHP $ _POST总是空的

时间:2014-02-04 20:23:15

标签: javascript php

Stumped,var-dump($ _ POST)总是返回数组[0] {} PHP邮件虽然总是成功。 html中的变量是我在调试器中查看时所期望的。打开和关闭register_globals都会失败。

 <!-- html code (in contact.php) -->
<form name="hhcform" method="POST" action="sendmail.php" onsubmit="return ValidateForm();"      enctype="text/plain"> 
First Name: <input type="text" name="firstname" value="" size="25">
<span id="firstnameErr" style="color:red">*</span>
<br><br>
Last Name: <input type="text" name="lastname" value="" size="25">
<span id="lastnameErr" style="color:red">*</span>
<br><br>
Email Address: <input type="text" name="emailaddress" value="" size="25">
<span id="emailErr" style="color:red">*</span>
<br><br>
Select a Topic: <span id="topicErr" style="color:red">*</span><br>
    <div class="radio-block">
        <input type="radio" name="topic" value="Insurance"> Accepted Insurance<br><br>
        <input type="radio" name="topic" value="Hours"> Office Hours<br><br>
        <input type="radio" name="topic" value="Refills"> Prescription Refills<br><br>
        <input type="radio" name="topic" value="Patients"> Accepting New Patients<br><br>
        <input type="radio" name="topic" value="Website"> Website Issues<br><br>
        <input type="radio" name="topic" value="Other"> Other<br><br>
    </div>
Comments: <span id="commentErr" style="color:red">*</span><br>
<textarea name="comments" rows="10" cols="25"></textarea><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset" onclick="ClearErrors();"><br><br>
</form>

PHP代码(在sendmail.php中)

 <?php
    var_dump($_POST);
    $firstname = $_POST['firstname'];
    $lastname =  $_POST['lastname'];
    $email = $_POST['emailaddress'];
    $topic = $_POST['topic'];
    $comments = $_POST['comments'];

    $recipient = "emailaddress@domainbame.com";
    $mailheader = "From: " . $email . "\r\n";
    if(mail($recipient, $topic, $comments, $mailheader))
    {
        echo "Email Sent, Thank You!" . " -" . "<a href='contact.php' 
        style='text-decoration:none;color:#ff0099;'> Return to Contact Us Form</a>";
    }
    else
    {
        echo "Email failed to send" . "-" . "<a href='contact.php' 
        style='text-decoration:none;color:#ff0099;'> Return to Contact Us Form</a>";
    }
?>

2 个答案:

答案 0 :(得分:3)

取出

enctype="text/plain" in the form, this should fix the issue.

答案 1 :(得分:0)

问题可能在于你的enctype

enctype="text/plain"

尝试

enctype="multipart/form-data" 

相反,除非你有充分的理由使用text / plain。