我正在wordpress中制作一个 php 表单。我想在这个表单中附加一个记事本或 PDF文件。例如,我在电子邮件中使用正文变量中的邮件函数获取所有这些
$body =" Attachment: $Attachmentfile";
我收到的不是文件,而是用户上传的文件名而不是文件。我正在尝试在电子邮件中接收文件。实际上,我也在学习如何去做。
我分配给 htm 文件标签的 php 代码是,
if(trim($_POST['Attachmentfile']) === '') {
$AttachmentfileError = 'Please enter a Pdf, Notepad or Word file.';
$hasError = true;
}
else
{
if($_FILES["Attachmentfile"]["name"] != "")
{
$strFilesName = $_FILES["Attachmentfile"]["name"];
$strContent = chunk_split(base64_encode(file_get_contents($_FILES["Attachmentfile"]["tmp_name"])));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
}
else
{
$Attachmentfile = trim($_POST['Attachmentfile']);
}
}
和我用于获取文件的 Html 代码,
<li class="left">
<label for="CV">Attachments :</label><span class="error">*</span><br>
<input class="txt" type="file" name="Attachmentfile" id="Attachmentfile" value="<?php if(isset($_POST['Attachmentfile'])) echo $_POST['Attachmentfile'];?>">
</li>
这是我的邮件功能代码,
$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "\r\n" . 'Content-type: text/html';
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
你能帮忙修改我的代码以便在电子邮件中获取文件吗?谢谢朋友。