This question already has an answer here:
- send email with attachment using php 5 answers
- php send email with attachment 5 answers
I have an ajax form located in https://nkaccounting.desertsunstudio.com/careers
It successfully moves the uploaded file to a folder called temp_cv in the root.
My question is how do i get that file that to attach to an email and send it using PHP? i was hoping to not use a library like phpmailer...
<form id="ajaxform_careers" action="/PHP/mailer.php" method="post" enctype="multipart/form-data">
<input type="text" name="name" placeholder="Full Name" required></input>
<input type="email" name="email" placeholder="Email" required></input>
<input type="text" name="uploadmsg" placeholder="Please Upload your CV (.docx or .pdf only)" disabled></input>
<div class="uploadbtn">
<p>Upload.</p>
<input type="file" name="cv_upload" accept="application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document"></input>
</div>
<textarea name="text" placeholder="Please write a brief description of yourself." required></textarea>
<input type='text' name='hmnvr' placeholder="Human verification: Man's best friend is a ..." required></input>
<button type="submit" name="submit" class="submit_btn" style="opacity: .7; cursor: default" disabled>Submit.</button>
</form>
<?php
if(isset($_FILES['cv_upload'])) {
$type = $_FILES["cv_upload"]['type'];
//----------correct file type-------------
if($type == "application/pdf" || $type == "application/msword" || $type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
//----------upload success-------------
$upload_dir = "../"."temp_cv/";
$tmp_name = $_FILES["cv_upload"]["tmp_name"];
$name = $_FILES["cv_upload"]["name"];
if(@move_uploaded_file($tmp_name, "{$upload_dir}{$name}")){
$headers = "From: NK Accounting <sal@desertsunstudio.com>
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
$name = $_POST['name'];
$email = $_POST ['email'];
$text = $_POST['text'];
$namer = $_FILES["cv_upload"]["name"];
$attachpath ="../"."temp_cv/"."".$namer."";
$msg ='Hello'
// heres were i would execute the mail function
} else {
//----------upload failure-------------
echo "<script>
$('textarea').text('error sending attachment; please reload the page and retry.');
</script>";
}
} else {
//----------wrong file type-------------
echo "<script>
$('textarea').text('only word or pdf documents.');
</script>";
}
}
?>
</div>