I am trying to send the file which is uploaded and gets saved to tmp directory as an attachment. I am using PhPMailer but i am getting Could not access file error. The mail is getting sent with text in it on clicking submit but file which gets uploaded is not getting sent. I have gone through similar type of asked questions but none could solve the issue. Here is the code.
<?php
if(isset($_POST['submit'])){
include('PHPMailer_5.2.0/class.phpmailer.php');
$content = 'Hello world!';
$email = new PHPMailer();
$email->From = 'info@example.com';
$email->FromName = 'Your Name';
$email->Subject = 'Subject';
$email->Body = $content;
$email->AddAddress( 'xxx@gmail.com' );
$email->AddAttachment( $_FILES['fileUpload']['tmp_name'], $_FILES['fileUpload']['name'] );
return $email->Send();
}
?>
<html>
<head>
<body>
<form id="sunrise" name="sunrise" method="post" action="">
<div class="form-group uploader col-xs-4">
<label class="coole" id="no-print">Upload Child's Image:</label>
<input name="fileUpload" type="file" id="fileUpload" class="no-print" required />
<br />
<div name="image-holder" id="image-holder"> </div>
</div>
<div class="col-xs-4">
<input type="text" name="student_name" class="form-control" id="add_student_first_name" placeholder='Your Name' required>
</div>
<button type="submit" class="btn btn-default" id="no-print" name="submit" value="submit">Submit</button>
</form>
<script>
$("#fileUpload").on('change', function() {
if (typeof(FileReader) != "undefined") {
var image_holder = $("#image-holder");
image_holder.empty();
var reader = new FileReader();
reader.onload = function(e) {
$("<img />", {
"src": e.target.result,
"class": "thumb-image",
"width": "113px",
"height": "151px"
}).appendTo(image_holder);
}
image_holder.show();
reader.readAsDataURL($(this)[0].files[0]);
} else {
alert("This browser does not support FileReader.");
}
});
</script>
<script type="text/javascript">
document.getElementById('date').valueAsDate = new Date();
</script>
</body>
</html>