I am making a php form in wordpress.I would like to attach a notepad or PDF file along this form.I am getting all this in email using mail function in a body variable for example
$body =" Attachment: $Attachmentfile";
Instead of file i am receiving file name that user uploading instead of file.I am trying to receive file in email.Actually i am learning too that how to do it.
My php code for assigning to htm file tag is,
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']);
}
}
and my Html code for getting file ,
<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>
and this is my mail function code,
$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
$headers .= "\r\n" . 'Content-type: text/html';
wp_mail($emailTo, $subject, $body, $headers);
$emailSent = true;
Can you help and modify my code in order to get file in email.Thanks friends.
this is an extract of one of my project .. change it according to your needs i wrote comment so that you get better better ..
call this function on form submit