Note that there are some explanatory texts on larger screens.

plurals
  1. POA attachment file with a php form in wordpress
    text
    copied!<p>I am making a php form in <strong>wordpress</strong>.I would like to attach a <strong>notepad or PDF</strong> file along this form.I am getting all this in email using mail function in a body variable for example </p> <pre><code>$body =" Attachment: $Attachmentfile"; </code></pre> <p>Instead of file i am receiving <strong>file name that user uploading</strong> instead of <strong>file</strong>.I am trying to receive file in email.Actually i am learning too that how to do it.</p> <p>My php code for assigning to htm file tag is, </p> <pre><code> 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']); } } </code></pre> <p>and my Html code for getting file , </p> <pre><code>&lt;li class="left"&gt; &lt;label for="CV"&gt;Attachments :&lt;/label&gt;&lt;span class="error"&gt;*&lt;/span&gt;&lt;br&gt; &lt;input class="txt" type="file" name="Attachmentfile" id="Attachmentfile" value="&lt;?php if(isset($_POST['Attachmentfile'])) echo $_POST['Attachmentfile'];?&gt;"&gt; &lt;/li&gt; </code></pre> <p>and this is my mail function code, </p> <pre><code>$headers = 'From: '.$name.' &lt;'.$emailTo.'&gt;' . "\r\n" . 'Reply-To: ' . $email; $headers .= "\r\n" . 'Content-type: text/html'; wp_mail($emailTo, $subject, $body, $headers); $emailSent = true; </code></pre> <p>Can you help and modify my code in order to get file in email.Thanks friends.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload