Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to create a front-end form that has an option to upload a CV (so pdf or word format) that I would like to be able to send as an email attachment. I've read a few articles and tutorials the most pertinent (link to article) which suggests something like this:

<?php
if ($_FILES) {
  foreach ($_FILES as $file => $array) {
  $newupload = insert_attachment($file,$post_id);
  //in this case ('upload_file', 'null')
  }
}
?>

<form method="post" action="<?php the_permalink(); ?>" enctype="multipart/form-data" >
  <input type="file" name="upload_file">
  <input type="submit">
<form>

In functions php:

function insert_attachment($file_handler,$post_id, $setthumb='false') {

  // check to make sure its a successful upload
  if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();

  require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  require_once(ABSPATH . "wp-admin" . '/includes/media.php');

  $attach_id = media_handle_upload( $file_handler, $post_id );

  return $attach_id;
 }

The problem is that this uploads the CV to the media library which I don't really want. I have put the rest of the code concerning the form here

How could I take $newupload and attach to to an email? (Ideally in the form of an attachment)

share|improve this question

1 Answer 1

up vote 0 down vote accepted

The problem is that this uploads the CV to the media library which I don't really want.

Instead of using media_handle_upload, try wp_handle_upload.

WordPress provides us with a wp_mail through which you can easily send an email with an attachment

share|improve this answer
    
Great, I'll look into it. –  mantis Nov 13 '13 at 10:44
    
I accepted your answer to this question (because it answers it :))but I'm actually getting getting an error which I'll post in a follow up question. –  mantis Nov 13 '13 at 11:42
    
Here is the follow-up question if you want to take a stab: wordpress.stackexchange.com/questions/123161/… –  mantis Nov 13 '13 at 12:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.