我正在尝试从表单发送附件。该电子邮件会生成一个附件,而不是我尝试上传的附件。我希望它上传并将名称更改为$strNewFileName
发送给用户时的名称。
html代码:
<input type="file" class="upload" name="uploaded_file[]" id="uploaded_file"></input>
.php 文件:
<?php
$strTo = "me@example.com";
$strSubject = "Document Updated";
$strMessage = nl2br($_GET["sqlCode"]);
$strNewFileName = $_GET["RevisedFileName"];
if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])) {
echo "File ". $_FILES['uploaded_file']['name'] ." uploaded successfully.\n";
echo "Displaying contents\n";
readfile($_FILES['uploaded_file']['tmp_name']);
} else {
echo "Possible file upload attack: ";
echo "filename '". $_FILES['uploaded_file']['tmp_name'] . "'.";
}
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: Document Update\r\nReply-To: example@example.com";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
rename("$strFilesName", "$strNewFileName");
// *** Attachment *** //
$strFilesName = $_FILES["uploaded_file"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["uploaded_file"]["name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/pdf; name=\"".$strNewFileName."\"\r\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment;\n\n";
$strHeader .= $strContent."\n\n";
$flgSend = @mail($strTo,$strSubject,$strMessage,$strHeader);
if($flgSend)
{
echo "Approval Send Complete.";
}
else
{
echo "Cannot send mail, Approval has not been processed.";
}
?>