1
這是一個簡單的PHP電子郵件表格,其中包含附件。表單工作正常,除了當文件上傳爲他們上傳的附件時,卻沒有內容。我相信這意味着上傳的附件文件沒有被正確解碼。這裏的代碼:電子郵件表格文件上傳返回文件空
<?php
$action = $_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" enctype="multipart/form-data" method="post">
<p>
<label>
<input type="checkbox" name="locate" id="locate ">
<strong>Locate an Installer</strong>
</label>
<strong>
<label>
<input type="checkbox" name="become" id="become">Become an Installer
</label>
</strong>
</p>
<div class="left">
Name:
<div>
<input name="name" type="text" id="name" size="40" />
</div>
</div>
<div class="left">
Email:
<div>
<input name="mailfrom" type="text" size="40" />
</div>
</div>
<div class="left">
Street:
<div>
<input name="street" type="text" id="street" size="40" />
</div>
</div>
<div class="left">
City:
<div>
<input name="city" type="text" id="city" size="40" />
</div>
</div>
<div class="left">
State:
<div>
<input name="state" type="text" id="state" size="10" /> Zip:
<input name="zip" type="text" id="zip" size="15" />
</div>
</div>
<div class="left">
Country:
<div>
<input name="country" type="text" id="country" size="40" />
</div>
</div>
<div class="left">
Phone:
<div>
<input name="phone" type="text" id="phone" size="40" />
</div>
</div>
<p>The fields above are REQUIRED<br>
<strong>
How did you hear about AirKrete<span style="font-size:11.0pt; ">®</span>? <br>Please make a selection.
<span id="sprycheckbox1">
<span class="checkboxRequiredMsg"></span>
</span>
</strong>
</p>
<div class="radiox"><label><input type="radio" name="Connection" value="friend" id="Connection_0">Friend</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="jobspec" id="Connection_1">Job Specification</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="hgtv" id="Connection_2">HGTV Promotion</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="web" id="Connection_3">Web Browsing</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="radio" id="Connection_4">Radio</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="tv" id="Connection_5">TV</label></div>
<div class="radiox"><label><input type="radio" name="Connection" value="other" id="Connection_6">Other</label></div></p>
<p class="clear-fix"> </p>
<div><p><strong>Comments:</strong><br></p></div>
<p><textarea name="Comments" cols="43" rows="10" id="Comments"></textarea></p>
<p><label>If you have Attachments....</label></p>
<p><input name="file_attachment" type="file" size="30" /></p>
<p>When completed please click Send Email Button</p>
<input type="submit" value="Send Email" name="action" />
<input type="hidden" name="redirect" value="http://www.airkrete.com/airkrete_thankyou.php" /><p>Thank You</p>
</form>
<?php
}
else /* send the submitted data */
{
$locate = isset($_REQUEST['locate']) ? $_REQUEST['locate'] : "" ;
$become = isset($_REQUEST['become']) ? $_REQUEST['become'] : "" ;
$mailfrom = $_REQUEST['mailfrom'];
$street = $_REQUEST['street'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$zip = $_REQUEST['zip'];
$country = $_REQUEST['country'];
$phone = $_REQUEST['phone'];
$connection = $_REQUEST['Connection'];
$comments = $_REQUEST['Comments'];
$name = $_REQUEST['name'];
$filename = "uploads/".basename($_FILES['file_attachment']['name']);
move_uploaded_file($_FILES["file_attachment"]["name"], $filename);
$file_size = $_FILES["file_attachment"]["size"]/1024;//size in KBs
$handle = fopen($filename, "a+");
$content = fread($handle, $file_size);
fclose($handle);
$content= chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
if ((($locate == "") && ($become == "")) || ($mailfrom == "") || ($street == "") || ($city == "") || ($state == "") || ($zip == "") || ($country == "") || ($phone == "") || ($name == ""))
{
echo "Not all required forms were filled out, please fill <a href=\"\">the form</a> again.";
}
else
{
if(($locate == "") && ($comments != "") && ($connection != ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about becoming an installer. My phone number is ".$phone.". I heard about you from: ".$connection."\r\n";
$message .= "I also left the following comment:\r\n".$comments."\r\n\r\n";
}
else if(($become == "") && ($comments != "") && ($connection != ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about locating an installer. My phone number is ".$phone.". I heard about you from: ".$connection."\r\n";
$message .= "I also left the following comment:\r\n".$comments."\r\n\r\n";
}
else if(($locate == "") && ($comments != "") && ($connection == ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about becoming an installer. My phone number is ".$phone."\r\n";
$message .= "I also left the following comment:\r\n".$comments."\r\n\r\n";
}
else if(($locate == "") && ($comments == "") && ($connection != ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about becoming an installer. My phone number is ".$phone.". I heard about you from: ".$connection."\r\n";
}
else if(($become == "") && ($comments != "") && ($connection == ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about locating an installer. My phone number is ".$phone.".\r\n";
$message .= "I also left the following comment:\r\n".$comments."\r\n\r\n";
}
else if(($become == "") && ($comments == "") && ($connection != ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about locating an installer. My phone number is ".$phone.". I heard about you from: ".$connection."\r\n";
}
else if(($locate == "") && ($comments == "") && ($connection == ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about becoming an installer. My phone number is ".$phone.".\r\n";
}
else if(($become == "") && ($comments == "") && ($connection == ""))
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about locating an installer. My phone number is ".$phone.".\r\n";
}
else
{
$message = "FROM: ".$name." <".$mailfrom.">\r\n";
$message .= "--".$uid."\r\n";
$message .= "Located: ".$street." ".$city." ".$state." ".$zip." ".$country."\r\n\r\n";
$message .= "I would like to inquire about become an installer and would also like to locate one. My phone number is ".$phone.". I heard about you from: ".$connection."\r\n";
$message .= "I also left the following comment:\r\n".$comments."\r\n\r\n";
}
if($filename != ""){
$message .= "Content-Type: application/octet-stream; name=\"http://airkrete.com/".$filename."\"\r\n"; // use different content types here
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"http://airkrete.com/".$filename."\"\r\n\r\n";
$message .= $content."\r\n\r\n";
}
$from = "From: $name<$mailfrom>\r\nReturn-path: $mailfrom";
$subject = "Someone's interested in either finding an installer or becoming one!";
mail("[email protected]", $subject, $message, $from);
echo "Email sent!";
}
}
?>
任何幫助將不勝感激。我可能完全錯誤,爲什麼上傳的文件上傳空白,但編碼是一個模糊的。
我試着刪除以下行:
$content= chunk_split(base64_encode($content));
無濟於事。有人有線索嗎?