我正在處理一個包含文件上傳的表單郵件,但該文件根本沒有顯示在測試電子郵件中。我調整了並重新調整了但無濟於事。有什麼建議麼?PHP文件上傳問題
形式的HTML部分被如下所示
<div class="contactleft">
<form action="former.php" method="post" enctype="multipart/form-data" id="former">
<div class="textbox"><span id="sprytextfield1">
<label for="fname"></label>
<input name="fname" type="text" class="inputer" id="fname" />
<span class="textfieldRequiredMsg">A value is required.</span></span></div><!-- End TectBox -->
<div class="textbox"><span id="sprytextfield2">
<label for="lname"></label>
<input name="lname" type="text" class="inputer" id="lname" />
<span class="textfieldRequiredMsg">A value is required.</span></span></div><!-- End TectBox -->
<div class="textbox"><span id="sprytextfield3">
<label for="email"></label>
<input name="email" type="text" class="inputer" id="email" />
<span class="textfieldRequiredMsg">A value is required.</span></span></div><!-- End TectBox -->
<div class="textbox"><span id="sprytextfield4">
<label for="file"></label>
<label for="file"></label>
<label for="fileField"></label>
<input type="file" name="fileField" id="fileField" />
<span class="textfieldRequiredMsg">A value is required.</span></span></div><!-- End TectBox -->
<div class="textbox">
<label for="sender"></label>
<input type="submit" name="sender" id="sender" value="click to send message" />
</div><!-- End TextBox -->
</form>
</div>
並且被如下所示
<?
$mailto = '[email protected]'; // insert the email address you want the form sent to
//$returnpage = 'thanks.php'; // insert the name of the page/location you want the user to be returned to//
$sitename = '[siteripe.com]'; // insert the site name here, it will appear in the subject of your email
/* Do not edit below this line unless you know what you're doing */
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'] ;
$file = $_POST['file'];
$subject = $_POST['subject'];
if (!eregi("^[a-z0-9]+([-_\.]?[a-z0-9])[email protected][a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z]{2,4}", $email)){
print("<strong>Error:</strong> this email address is not in a valid format.<br/><br/><a href='javascript:history.go(-1)'>Back</a>");
exit;
}
$message = "\n$name submitted the following message:\n\n$message\n\n$name's contact details are as follows:\n\nFirst Name: $fname\nLast Name: $lname\nEmail Address: $email\nForm: $file";
mail($mailto, "$subject", $message, "From: $email");
?>
郵件函數返回成功的嘗試是$ var =郵件真..和看到的響應 – 2012-03-30 00:42:55
嘛,$ _ POST [「文件」]總是會失敗,因爲你的文件上傳輸入被命名爲'fileField'。嘗試$ _POST ['fileField'],如果你在文件名後面。 – 2012-03-30 00:44:08