0

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']);
}
}

および file を取得するための私の 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;

電子メールでファイルを取得するために私のコードを変更して助けてもらえますか。ありがとうございます。

4

1 に答える 1