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:

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">

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)

1 Answer 1


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

  • Great, I'll look into it.
    – mantis
    Commented Nov 13, 2013 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
    Commented Nov 13, 2013 at 11:42
  • Here is the follow-up question if you want to take a stab: wordpress.stackexchange.com/questions/123161/…
    – mantis
    Commented Nov 13, 2013 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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