I have an HTML form and I am using phpMailer. When completing the form and clicking submit all data entered in the text input fields etc work as expected. However, when I attach a file to the input type "file" when receiving the email no attachment is there.
Does anyone have any suggestions as to why the attachment is not attached?
FYI - at current, the site has no SSL certificate and the emails are going to the spam folder - could this be the issue?
I' am new to phpMailer and have been able to achieve the below by research.
phpMailer()
<?php
$file = $_POST['file'];
// more variables...
$CustomerSignature = $_POST['q21'];
$Date = $_POST['q22'];
$filename = "./upload/" . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],"./upload/" . $_FILES["file"]["name"]);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
require 'phpMailer/src/Exception.php';
require 'phpMailer/src/PHPMailer.php';
require 'phpMailer/src/SMTP.php';
require 'phpMailer/src/OAuth.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Username = '######';
$mail->Password = '######';
$mail->isHTML(true);
$mail->setFrom('######', '######');
$mail->addReplyTo('######', '######');
$mail->addAddress('######', '######');
$mail->addAddress('######');
$mail->AddAttachment($filename);
$mail->Subject = 'New Credit Application';
$mail->Body = '<b>New Credit Application (Online)!</b></br>'
.'Trading Name: '.$TradingName.'</br>'
.'blah blah blah etc.'
.'Customer Signature: '.$CustomerSignature.'</br>'
.'Date: '.$Date.'</br>';
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'The email message was sent.';
}
?>
HTML file attachment part:
<form method="POST" action="testmail2.php" id="myform" class="fs-form fs-form-full" autocomplete="off">
<ol class="fs-fields">
<li>
<label class="fs-field-label fs-anim-upper" for="file">Attachment</label>
<input class="fs-anim-lower" id="file" name="file" type="file" required/>
</li>