title: How to upload file to custom folder and send attachment to email in wordpress
body: <p>I have a some trouble with understanding in uploading and sending attachment.
  For example: </p>
  
  <pre><code>$zip_code = $_POST['zip_code'];
  $phone = $_POST['phone'];
  $email = $_POST['email'];
  $attachments = '';
  if (!empty($_FILES['attachment']['tmp_name'])) {
      $path = $_FILES['attachment']['name'];
      if (copy($_FILES['attachment']['tmp_name'], $path)) $attachments = $path;
  }
  
  $subject = 'You have message from ' . get_bloginfo('name');
  $message = '&lt;table width="100%" cellspacing="0" cellpadding="5" border="0"&gt;';
  $message .= '&lt;tr&gt;&lt;td width="150px"&gt;&lt;b&gt;Zip Code:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;' . $zip_code . '&lt;/td&gt;&lt;/tr&gt;';
  $message .= '&lt;tr&gt;&lt;td width="150px"&gt;&lt;b&gt;Phone:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;' . $phone . '&lt;/td&gt;&lt;/tr&gt;';
  $message .= '&lt;tr&gt;&lt;td width="150px"&gt;&lt;b&gt;Email:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;' . $email . '&lt;/td&gt;&lt;/tr&gt;';
  $message .= '&lt;tr&gt;&lt;td width="150px"&gt;&lt;b&gt;Attachments:&lt;/b&gt;&lt;/td&gt;&lt;td&gt;' . $attachments . '&lt;/td&gt;&lt;/tr&gt;';
  $message .= '&lt;/table&gt;';
  //php mailer variables
  $to = get_option('admin_email');
  $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  $headers .= "Content-Disposition: attachment; filename = \"" . $attachments . "\"\n\n";
  $sent = wp_mail($to, $subject, $message, $headers, $attachments);
  </code></pre>
  
  <p>This code work not correctly. Email and attachment sending correctly, but file upload in root directory. And when I upload the same files, new file overwrite old file. I don't understand how I can add some hash tag to file name.</p>
  
  <p>Maybe U can help me? Any ideas or where I can read how to resolve this issue.</p>
  
  <p>Thanks! </p>