I have this following piece of code of PHPMailer. The problem is, that the file uploads to the server successfully but the attachment is not sent in the mail.
Here is HTML:
<div class="image-upload"><label for="file-input">
<p>Upload File</p></label><input id="file-input" name="file" type="file"/>
</div>
And PHP is
if (isset($_POST['submit'])) {
if (!isset($_SESSION['mail_send'])) {
require'PHPMailer/class.phpmailer.php';
// $mail = new PHPMailer();
$fileName = '';
$filePath = '';
$type = '';
$name = $_POST['name'];
$phone = "Phone number : " . $_POST['phone'];
$email = $_POST['email'];
$country = "Country : " . $_POST['country'];
$dropdown = "Services:" . (isset($_POST['options']) ? implode(", ", `enter code here`array_map("htmlspecialchars", $_POST['options'])) : " not selected ") . "<br />"; // Multimple select box
$allowedExts = array("doc", "docx", "xls", "xlsx", "pdf", "png", "jpg", "jpeg", "gif");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/excel")
|| ($_FILES["file"]["type"] == "application/vnd.ms-excel") || ($_FILES["file"]["type"] == "application/x-excel") || ($_FILES["file"]["type"] == "application/x-msexcel")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|| ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/gif")) && in_array($extension, $allowedExts)) {
if ($_FILES["file"]["error"] > 0) {
echo "<script>alert('Error: " . $_FILES["file"]["error"] . "')</script>";
} else {
$d = 'upload/';
$de = $d . basename($_FILES['file']['name']);
move_uploaded_file($_FILES["file"]["tmp_name"], $de);
$fileName = $_FILES['file']['name'];
}
} else {
echo "<script>alert('Invalid file')</script>";
exit();
}
$detail = "Message : " . $_POST['details'];
$message = '<html>
<head>
<meta http-equiv=\"Content-Type: multipart/alternative; boundary=$boundary". "
". />
<title>Verify Your Account</title>
</head>
<body>
<div>' . $phone . '</div>
<div>' . $country . '</div>
<div>' . $dropdown . '</div>
<div>' . $detail . '</div>
</body>
</html>';
$mail = new PHPMailer();
$mail->From = $email;
$mail->FromName = $name;
$mail->IsHTML(true);
$mail->AddAddress('mushahid.hussain@app-desk.com');
$mail->Subject = 'Get a Quote';
$mail->MsgHtml($message);
$mail->AddAttachment("upload/$fileName");
$mail->Send();
}
}
I have also checked with
$mail->Body = $message;
$mail->AddAttachment("upload/$fileName");