title: wp_mail() - Sending 'file' input type from form as attachment
body: <p>I have shortcode that creates and validates a form in my fucntions.php file. After the form is submitted and validated, the data is then stored in SESSION variables. The SESSION variables are used to carry the information to a custom PHP template page. This page emails the form data using wp_mail() and displays a thank you note. </p>
  
  <p>My issue is that the form has a 'file' input type for an image upload. I have it validated correctly, but transferring the uploaded image and then emailing it as an '$attachments" in the wp_mail() function is something I am struggling with. </p>
  
  <p>Also I know I should save the uploaded image in a temp folder instead of storing it in a SESSION variable. And then I will just have to delete the image after the email is sent. </p>
  
  <p>My question is HOW? The code for all of this is very long so here are the short and sweet versions:</p>
  
  <p>functions.php (in a shortcode function)</p>
  
  <pre><code>&lt;?php
  $file = "";
  $fileErr = "";
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
  
     //file upload is required, make sure its not empty
     if(empty($_FILES['pmFile'])){
         $fileErr = "This is required!";
     }
     else{
         $file = $_FILES['pmFile'];//I validate here, but lets just say its OK     
     } 
  
     //If the error message is empty, store data in SESSION variables, and 
     //uploaded file in temp folder + redirect to thank you page
     if(empty($fileErr)){
  
        //HOW DO I SAVE THE FILE TEMPORARILY FOR USE ON THE NEXT PAGE??? 
  
        wp_redirect( '../wp-content/themes/rest of the path/thankYouPage.php' );
        exit();
  
     }else{ /*display errors*/}
  
  }
  
  //down here is where I wrote the code for the form. YES method=post, YES I 
  //included enctype="multipart/form-data, YES the file input name is in fact 
  //'pmFile'.
  ?&gt;
  </code></pre>
  
  <p>thankYouPage.php</p>
  
  <pre><code>//initial page stuff 
  //start email setup
  $to = 'XXXXX@gmail.com';
  
  $email_from = 'XXXXX@gmail.com';
  $email_subject = "New Price Match Request";
  $email_body = "I display the html and data here";
  
  //for attachments
  //HOW DO I PULL THAT UPLOADED FILE FROM THE TEMP FOLDER AND SEND IT AS AN ATTACHMENT?
  $attachments = (the file in temp folder);
  //NOW HOW TO I DELETE IT FROM THE TEMP FOLDER
  
  $headers = "From: $email_from \r\n";
  $headers .= "Reply-To: $email \r\n"; //$email is a SESSION variable pulled from before
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  
  //set to html
  add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
  
  //send
  wp_mail( $to, $email_subject, $email_body, $headers, $attachments );
  
  // Reset content-type to avoid conflicts
  remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
  </code></pre>
  
  <p>I know a lot of the code it removed, but email works for all of the other information in the form being transferred by SESSION variables. I really just need to know how to transfer this uploaded file and email it. Thanks!</p>