0

I am trying to make a form with a file upload line that sends as an attachment. I'm getting the email with the $body but no attachment I've looked over the code and done research everywhere so now I'm here, Any suggestions?

The PHP Code

if ( isset( $_FILES['upload'] ) && $_FILES['upload']['error'] == UPLOAD_ERR_OK ) {
        $mail->IsHTML(true);
        $mail->AddAttachment( $_FILES['upload']['tmp_name'], $_FILES['upload']['name'] );
    }

The HTML Code

<form action="include/contractor.php" method="post" enctype="multipart/form-data">                
<label for="upload">File</label>
<input type="file" name="upload" id="upload" /></form>
  • 3
    Apparently "everywhere" didn't include the example scripts included with PHPMailer that show you exactly how to do this. – Synchro Apr 05 '16 at 17:07

3 Answers3

0

I just do this uploading file to one folder, and references this file with your permanent address. Make a test with an existing file on your server and if it´s solve your problem modify your script to save file in a folder before send.

NIZZOLA
  • 39
  • 8
0

I like bullet points so I will bullet the solution to your issue:

As A note I would also say it could well be likely that your server system (might) have in place a restriction that temporary files freshly uploaded, tmp_name , their access is restricted. So use move_uploaded_file to save the file to a "real" destination before attaching to the email sender.

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
0

For starters, you need to actually have a way to upload the file to attach which would be some separate code than you have listed. When you add a file to Google mail, for example, you have to upload the file itself.

Without seeing the rest of your code I can't give a more explicit solution.

Adam Gerard
  • 708
  • 2
  • 8
  • 23