I created a form for my customers to submit their comment:
<form role="form" action="comment.php" method="post" class="col-md-6 col-md-offset-3" enctype="multipart/form-data">
<div>
<div class="form-group">
<label>Email<span style="color:gray;"> (optional)</span></label>
<input type="email" name="email" class="form-control">
</div>
<div class="form-group">
<label>Description<span style="color:red;"> *</span></label>
<textarea class="form-control" name="description" rows="3" required></textarea>
</div>
<div class="form-group">
<label>Attach your file</label>
<input type="file" name="file">
</div>
<div style="margin-top: 25px; direction: rtl;">
<div class="form-group">
<button type="submit" name="submit" value="yes" class="btn btn-info">Send Comment</button>
</div>
</div>
</div>
</form>
I used PHPMailer for sending Email in comment.php
:
if($g_ok == 1){
$email = new PHPMailer();
$email->From = 'noreply@ideanetwork.co';
$email->FromName = 'Idea Network Ticketing';
$email->Subject = 'New comment from ticketing portal';
$email->Body = $bodytext;
$email->AddAddress( 'submitcomments@ideanetwork.co' );
$email->WordWrap = 70;
if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
$info = pathinfo($_FILES['file']['name']);
$ext = $info['extension'];
if ($ext == "php" or $ext == "exe" or $ext == "msi"){
header("location:../php/accessdenied.php");
exit;
}
else{
if (filesize($_FILES['file']['tmp_name']) > 4194304){
$filenote .= "Maximum file size must be 4 MB.";
}
else{
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $_FILES['file']['tmp_name']);
$email->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name'], $encoding = 'base64', $mime_type);
}
}
}
if(!$email->Send()){
$filenote .= "<script>alert('Mailer Error: " . $email->ErrorInfo."')</script>";
}
else{
$ok = 1;
}
}
also I tried this code:
$email->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']);
when I tested my form, every things were OK except attached file! my email size is true, for example when I attach an image with size 150KB, my received email size is 150KB too, but that haven't any attached file. instead of file I received a long unclear text and some information about attached file in header and footer like this:
boundary="b1_2d997b3e49a2cbf59277c329683b668e" Content-Transfer-Encoding: 8bit
This is a multi-part message in MIME format.
--b1_2d997b3e49a2cbf59277c329683b668e Content-Type: text/plain; charset=us-ascii
in header and:
--b1_2d997b3e49a2cbf59277c329683b668e Content-Type: image/jpeg; name="apple.jpg" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=apple.jpg
/9j/4AAQSkZJRgABAQEASABIAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdC ........(hundreds of lines like this).............. JAkwgptNz//Z
--b1_2d997b3e49a2cbf59277c329683b668e--
in footer
my PHP version: 5.5