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)