Phpmailler Attachment with Tmp name

Asked

Viewed 26 times

0

I have the following code in PHP, using Phpmailer to send by email files of a multiple upload, is working the problem is that in the email the name of the files is with the name of the folder tmp for example : "/tmp/php/Z9MDY7" instead of appearing the name of the file that was attached, but in the folder of the server to which these same files go the name is correct, which could be?

Code:

$total = count($_FILES['pdfanexo']['name']);

for($i=0; $i<$total; $i++) {                                              
    $tmpFilePath = $_FILES['pdfanexo']['tmp_name'][$i];
    if ($tmpFilePath != ""){
        $newFilePath = "Marcas/" .$vregistro. $d. "/". $_FILES['pdfanexo']['name'][$i];
        if(move_uploaded_file($tmpFilePath, $newFilePath)) {            
            $mail->addAttachment($newFilePath, $tmpFilePath);       //Attachment Documentos Múltiplo Upload (PDF-DOCUMENT)  
        }
    }
}

1 answer

1


The addAttachment method declaration is:

/**
 * Add an attachment from a path on the filesystem.
 * Returns false if the file could not be found or read.
 * @param string $path Path to the attachment.
 * @param string $name Overrides the attachment name.
 * @param string $encoding File encoding (see $Encoding).
 * @param string $type File extension (MIME) type.
 * @param string $disposition Disposition to use
 * @throws phpmailerException
 * @return bool
*/
public function addAttachment($path, $name = '', $encoding = 'base64', $type = '', $disposition = 'attachment')

And you’re passing the $tmpFilePath instead of the file name in the second parameter. Try the exchange below:

Of:

$mail->addAttachment($newFilePath, $tmpFilePath);

To:

$mail->addAttachment($newFilePath, $_FILES['pdfanexo']['name'][$i]);
  • Perfect, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.