I want to send an attachement file by the user from an html form and send it by email with PHPMailer.
I can send every input, except the attachement, can you please help... Here's my HTML form code
...
<div class="form-group">
<input type="file" id="Attachment" class="form-control-textarea" placeholder=" Upload file:" name="Attachment" style="text-decoration: underline"></input>
</div>
<div class="form-group">
<button onClick="sendContact();" type="button" class="form-control-submit-button" name="submit">Submit</button>
</div>
</form>
Now the Jquery that send form inputs to PHPMailer:
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function sendContact()
{
var valid;
valid = validateContact();
if(valid)
{
jQuery.ajax(
{
url: "mail_handler.php",
/*data: $("#ContactFrm").serialize(), */
data: new FormData(this), // grab all form contents including files
type: "POST",
success:function(data)
{
$("#feedback").html(data);
I use FormData() to grab the file information.
Finally the PHP code:
$file_to_attach = $_FILES['Attachment']['tmp_name'];
$filename = $_FILES['Attachment']['name'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->addAttachment($file_to_attach, $filename);
Like I said email is sent but no attachment...
Thanks