I have uploaded a file using jquery and now i need to send that uploaded file in mail as an attachment.Refer fiddle file upload.How to send this upload in mail as an attachment.
HTML
<form id="myform" action="process-upload.php" method="post" enctype="multipart/form-data">
<input id="tele" type="file" name="filename"/>
<br/>
<input class="formbtn" type="submit" value="Upload" />
jquery
$(document).ready(function () {
$('#myform').validate({
rules: {
filename: {
required: true,
extension: "docx|rtf|doc|pdf"
}
},
messages: {
filename: {
required: "Please upload resume",
extension: "Please upload valid file formats"
}
}
});
});
php
<?php
require("class.phpmailer.php");
$email = new PHPMailer();
$email->From = 'from@mail.com';
$email->FromName = 'Name';
$email->Subject = 'Subject';
$email->Body = 'Message Body';
$email->AddAddress( 'abc@gmail.com' );
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
$email->AddAttachment(basename($target_path . $_FILES['uploadedfile']['name']));
return $email->Send();
?>