简体   繁体   中英

Phpmailer will not send attachments

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>

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM